ecshop修改注册、增加手机号码注册

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

1.去掉“用户名”注册

a.去掉提交

user_passport.dwt页面去掉 <input name="username" type="text" size="30" id="username" onblur="is_registered(this.value);" class="input_login" />提交

b.去掉js表单验证,user.js

去掉,var username  = Utils.trim(frm.elements['username'].value);   第439行

去掉,

if (username.length == 0)
  {
    msg += username_empty + '\\n';
  }
  else if (username.match(/^\\s*$|^c:\\\\con\\\\con$|[%,\\'\\*\\"\\s\\t\\<\\>\\&\\\\]/))
  {
    msg += username_invalid + '\\n';
  }
  else if (username.length < 3)
  {
    //msg += username_shorter + '\\n';
  }

c.在php代码中,去掉相关的验证 (检测用户名长度),user.php 第40行

在elseif ($action == 'act_register'),去掉

/*if (strlen($username) < 3)
        {
            show_message($_LANG['passport_js']['username_shorter']);
        }*/

注意:下面代码可以选择去掉,也可以选择不去掉。如果不去掉,则只需要把username的值设置不想等就可以了(可以把username的值等于当前时间,则username=time())。那么d,e步骤可以不需要修改

$username = isset($_POST['username']) ? trim($_POST['username']) : '';

 

推荐解决办法1,user.php:username=isset(_POST['email']) ? trim($_POST['email']) : '';

推荐解决办法2,user.php: $username = gmtime();

 

 /*以下验证有点小问题 会出现 UNKNOWN ERROR! 提示*/

d.去掉验证(检测用户名是否为空),lib_passport.php 

if (empty($username))
    {
        $GLOBALS['err']->add($GLOBALS['_LANG']['username_empty']);
    }
    else
    {
        if (preg_match('/\\'\\/^\\\\s*$|^c:\\\\\\\\con\\\\\\\\con$|[%,\\\\*\\\\"\\\\s\\\\t\\\\<\\\\>\\\\&\\'\\\\\\\\]/', $username))
        {
            $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_invalid'], htmlspecialchars($username)));
        }
    }

 e.去掉验证(检测用户名是否已经存在),lib_passport.php  第87行

/*elseif ($GLOBALS['user']->error == ERR_USERNAME_EXISTS)
        {
            $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_exist'], $username));
        }*/

 

2.增加手机验证功能

a.html代码

<tr>
          <td align="right">手机:</td>
          <td>
          <input name="mobile_phone" type="text"  class="input_login" id="mobile_phone" onblur="checkMobile(this.value);" size="30"/>
            <span  style="color:#FF0000"> *</span>
          </td>
        </tr>
        <tr>
          <td align="right">&nbsp;</td>
        <td><span id="mobile_notice" class="red"></span>&nbsp;</td></tr>

b.增加js代码,checkMobile效果,user.js

function checkMobile(mobile)
{
  var submit_disabled = false;
  mobile = Utils.trim(mobile);
  
  if (mobile == '')
  {
    document.getElementById('mobile_notice').innerHTML = '* 手机号码不能为空';
    submit_disabled = true;
  }else if(mobile.length !=11){
     document.getElementById('mobile_notice').innerHTML = '* 不是一个有效的手机号码';
    submit_disabled = true; 
  }
 
  if( submit_disabled )
  {
    document.forms['formUser'].elements['Submit'].disabled = 'disabled';
    return false;
  }
  Ajax.call( 'user.php?act=check_mobile', 'mobile=' + mobile, check_mobile_callback , 'GET', 'TEXT', true, true );
}
function check_mobile_callback(result){
    if ( result == 'ok' )
      {
        document.getElementById('mobile_notice').innerHTML = '* 可以注册';
        document.forms['formUser'].elements['Submit'].disabled = '';
      }
      else
      {
        document.getElementById('mobile_notice').innerHTML = '* 手机已经被注册,请重新输入';
        document.forms['formUser'].elements['Submit'].disabled = 'disabled';
      }    
}

c.增加Ajax访问check_mobile,user.php 第302行

elseif($action == 'check_email')
{
    $email = trim($_GET['email']);
    if ($user->check_email($email))
    {
        echo 'false';
    }
    else
    {
        echo 'ok';
    }
}
/*增加代码*/
elseif($action == 'check_mobile'){
    $mobile = trim($_GET['mobile']);
    $sql = 'SELECT user_name, email FROM ' . $ecs->table('users') . " WHERE mobile_phone = '$mobile'";
    $row = $db->getRow($sql);
    if($row){
        echo 'false';    
    }else{
        echo 'ok';    
    }
}

/*End*/

(责任编辑:chinab4c)