分享

开发ecshop新注册用户后台审核确认功能

 秋天的童话980 2017-09-27
需求: 1. 新注册的用户需要后台管理员进行确认之后才能成为正式用户。 2. 新用户注册之后,提示请等待管理员确认后才能使用。 3. 新注册的用户,如果管理员没有对其注册身份进行

ecshop需求:

1. 新注册的用户需要后台管理员进行确认之后才能成为正式用户。

2. 新用户注册之后,提示请等待管理员确认后才能使用。

3. 新注册的用户,如果管理员没有对其注册身份进行确认,在登录时会提示请等待管理员确认之后才能登录。

在观察数据库表的时候发现,users表中有个is_validated字段,默认是0,表明没有通过验证。我们基于这个字段来实现本文要求的功能。

升级说明

新注册的ecshop用户需要后台管理员确认之后才能成为正式注册的用户。在用户提交注册信息之后,提示用户管理员会通过电话对其身份进行确认。未确认的用户无法登录,未确认用户登录时会提示需要确认的信息。

升级方法

【1】在languages\zh_cn\admin\users.php中增加:

  1. $_LANG['invalid_is_validated'] = '只能输入0或1。0为无效,1为有效';  

【2】在languages\zh_cn\user.php中增加:

  1. $_LANG['login_failure_invalid'] = '需管理员确认身份之后才能登陆';  

【3】修改includes\modules\integrates\integrate.php中的login函数为:

  1. /**
  2.    *  用户登录函数
  3.    *
  4.    * @access  public
  5.    * @param   string $username
  6.    * @param   string $password
  7.    *
  8.    * @return int
  9.    */
  10. function login($username,$password$remember = null)  
  11.   {  
  12. $rt = $this->check_user($username$password);  
  13. if ($rt > 0)  
  14.       {  
  15. if($this->need_sync)  
  16.           {  
  17. $this->sync($username,$password);  
  18.           }  
  19. $this->set_session($username);  
  20. $this->set_cookie($username$remember);  
  21. return 1;  
  22.       }  
  23. elseif ($rt == -1)  
  24.       {  
  25. //If the user is not valid, returns -1.
  26. return -1;  
  27.       }  
  28. else
  29.       {  
  30. return 0;  
  31.       }  
  32.   }  

修改add_user函数为:

  1. /**
  2.      *  添加一个新用户
  3.      *
  4.      * @access  public
  5.      * @param
  6.      *
  7.      * @return int
  8.      */
  9.     functionadd_user($username$password$email$gender = -1, $bday = 0, $reg_date=0,$md5password='')  
  10.     {  
  11. /* 将用户添加到整合方 */
  12. if($this->check_user($username) != 0)  
  13.         {  
  14. $this->error =ERR_USERNAME_EXISTS;  
  15. return false;  
  16.         }  
  17. /* 检查email是否重复 */
  18. $sql = 'SELECT' . $this->field_id .  
  19. ' FROM' . $this->table($this->user_table).  
  20. ' WHERE' . $this->field_email . ' = '$email'';  
  21. if($this->db->getOne($sql, true) > 0)  
  22.         {  
  23. $this->error =ERR_EMAIL_EXISTS;  
  24. return false;  
  25.         }  
  26. $post_username =$username;  
  27. if ($md5password)  
  28.         {  
  29. $post_password =$this->compile_password(array('md5password'=>$md5password));  
  30.         }  
  31. else
  32.         {  
  33. $post_password =$this->compile_password(array('password'=>$password));  
  34.         }  
  35. $fields =array($this->field_name, $this->field_email, $this->field_pass);  
  36. $values =array($post_username$email$post_password);  
  37. if ($gender > -1)  
  38.         {  
  39. $fields[] =$this->field_gender;  
  40. $values[] =$gender;  
  41.         }  
  42. if ($bday)  
  43.         {  
  44. $fields[] =$this->field_bday;  
  45. $values[] = $bday;  
  46.         }  
  47. if ($reg_date)  
  48.         {  
  49. $fields[] =$this->field_reg_date;  
  50. $values[] =$reg_date;  
  51.         }  
  52. $sql = 'INSERTINTO ' . $this->table($this->user_table).  
  53. ' ('. implode(','$fields) . ')'.  
  54. ' VALUES('' . implode('', ''$values) . '')';  
  55. $this->db->query($sql);  
  56. if($this->need_sync)  
  57.         {  
  58. $this->sync($username$password);  
  59.         }  
  60. return true;  
  61.     }  

【4】修改includes\modules\integrates\ecshop.php文件内容为:

  1. /**
  2.  * ECSHOP 会员数据处理类
  3.  *============================================================================
  4.  * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。
  5.  * 网站地址: http://www.
  6.  * ----------------------------------------------------------------------------
  7.  * 这是一个免费开源的软件;这意味着您可以在不用于商业目的的前提下对程序代码
  8.  * 进行修改、使用和再发布。
  9.  *============================================================================
  10.  * $Author: liubo $
  11.  * $Id: ecshop.php 172172011-01-19 06:29:08Z liubo $
  12.  */
  13. if (!defined('IN_ECS'))  
  14. {  
  15. die('Hacking attempt');  
  16. }  
  17. /* 模块的基本信息 */
  18. if (isset($set_modules) && $set_modules == TRUE)  
  19. {  
  20. $i = (isset($modules)) ?count($modules) : 0;  
  21. /* 会员数据整合插件的代码必须和文件名保持一致 */
  22. $modules[$i]['code']    = 'ecshop';  
  23. /* 被整合的第三方程序的名称 */
  24. $modules[$i]['name']    = 'ECSHOP';  
  25. /* 被整合的第三方程序的版本 */
  26. $modules[$i]['version'] ='2.0';  
  27. /* 插件的作者 */
  28. $modules[$i]['author']  = 'ECSHOPR&D TEAM';  
  29. /* 插件作者的官方网站 */
  30. $modules[$i]['website'] ='http://www.';  
  31. return;  
  32. }  
  33. require_once(ROOT_PATH .'includes/modules/integrates/integrate.php');  
  34. class ecshop extends integrate  
  35. {  
  36. var$is_ecshop = 1;  
  37. var$is_validated = '0';  
  38. function __construct($cfg)  
  39.     {  
  40. $this->ecshop($cfg);  
  41.     }  
  42. /**
  43.      *
  44.      *
  45.      * @access  public
  46.      * @param
  47.      *
  48.      * @return void
  49.      */
  50. function ecshop($cfg)  
  51.     {  
  52.        parent::integrate(array());  
  53. $this->user_table ='users';  
  54. $this->field_id ='user_id';  
  55. $this->ec_salt ='ec_salt';  
  56. $this->field_name ='user_name';  
  57. $this->field_pass ='password';  
  58. $this->field_email= 'email';  
  59. $this->field_gender= 'sex';  
  60. $this->field_bday ='birthday';  
  61. $this->field_reg_date = 'reg_time';  
  62. $this->need_sync =false;  
  63. $this->is_ecshop =1;  
  64. $this->is_validated= 'is_validated';  
  65.     }  
  66. /**
  67.      *  检查指定用户是否存在及密码是否正确(重载基类check_user函数,支持zc加密方法)
  68.      *
  69.      * @access  public
  70.      * @param   string $username   用户名
  71.      *
  72.      * @return  int
  73.      */
  74.     functioncheck_user($username$password = null)  
  75.     {  
  76. if ($this->charset!= 'UTF8')  
  77.         {  
  78. $post_username =ecs_iconv('UTF8'$this->charset, $username);  
  79.         }  
  80. else
  81.         {  
  82. $post_username =$username;  
  83.         }  
  84. if ($password ===null)  
  85.         {  
  86. $sql ='SELECT ' . $this->field_id .  
  87. ' FROM' . $this->table($this->user_table).  
  88. 'WHERE ' . $this->field_name . '='' . $post_username .''';  
  89. return$this->db->getOne($sql);  
  90.         }  
  91. else
  92.         {  
  93. //We also get theis_validated value
  94. $sql = 'SELECTuser_id, password, is_validated, salt,ec_salt ' .  
  95. ' FROM' . $this->table($this->user_table).  
  96. 'WHERE user_name='$post_username'';  
  97. $row =$this->db->getRow($sql);  
  98. $ec_salt=$row['ec_salt'];  
  99. if (empty($row))  
  100.             {  
  101. return 0;  
  102.             }  
  103. $is_validated =$row['is_validated'];  
  104. if (0 ==$is_validated)  
  105.             {  
  106. //We use -1 denote that that user resigsteredby not validated.
  107. return -1;  
  108.             }  
  109. if(empty($row['salt']))  
  110.             {  
  111. if($row['password'] !=$this->compile_password(array('password'=>$password,'ec_salt'=>$ec_salt)))  
  112.                 {  
  113. return 0;  
  114.                 }  
  115. else
  116.                 {  
  117. if(empty($ec_salt))  
  118.                           {  
  119. $ec_salt=rand(1,9999);  
  120. $new_password=md5(md5($password).$ec_salt);  
  121. $sql = 'UPDATE'.$this->table($this->user_table).'SET password= ''.$new_password.'',ec_salt=''.$ec_salt.'''.  
  122. 'WHERE user_name='$post_username'';  
  123. $this->db->query($sql);  
  124.                             }  
  125. return$row['user_id'];  
  126.                 }  
  127.             }  
  128. else
  129.             {  
  130. /* 如果salt存在,使用salt方式加密验证,验证通过洗白用户密码*/
  131. $encrypt_typesubstr($row['salt'], 0, 1);  
  132. $encrypt_saltsubstr($row['salt'], 1);  
  133. /* 计算加密后密码 */
  134. $encrypt_password = '';  
  135. switch($encrypt_type)  
  136.                 {  
  137.                     caseENCRYPT_ZC :  
  138. $encrypt_password = md5($encrypt_salt.$password);  
  139. break;  
  140. /* 如果还有其他加密方式添加到这里  */
  141. //caseother :
  142. //  ----------------------------------
  143. //  break;
  144.                     caseENCRYPT_UC :  
  145. $encrypt_password = md5(md5($password).$encrypt_salt);  
  146. break;  
  147. default:  
  148. $encrypt_password = '';  
  149.                 }  
  150. if($row['password'] != $encrypt_password)  
  151.                 {  
  152. return 0;  
  153.                 }  
  154. $sql ='UPDATE ' . $this->table($this->user_table) .  
  155. 'SET password = ''$this->compile_password(array('password'=>$password)) . '',salt='''.  
  156. 'WHERE user_id = '$row[user_id]'';  
  157. $this->db->query($sql);  
  158. return$row['user_id'];  
  159.             }  
  160.         }  
  161.     }  
  162. /**
  163.      *  编辑用户信息($password, $email, $gender, $bday) 重载父类的方法
  164.      *
  165.      * @access  public
  166.      * @param
  167.      *
  168.      * @return void
  169.      */
  170. function edit_user($cfg)  
  171.     {  
  172. if (empty($cfg['username']))  
  173.          {  
  174. return false;  
  175.          }  
  176. else  //www.
  177.          {  
  178. $cfg['post_username'] = $cfg['username'];  
  179.          }  
  180. $values = array();  
  181. if (!empty($cfg['password']) && empty($cfg['md5password']))  
  182.          {  
  183. $cfg['md5password'] = md5($cfg['password']);  
  184.          }  
  185. if ((!empty($cfg['md5password'])) &&$this->field_pass != 'NULL')  
  186.          {  
  187. $values[] = $this->field_pass . '='' .$this->compile_password(array('md5password'=>$cfg['md5password'])) .''';  
  188.          }  
  189. if ((!empty($cfg['email'])) && $this->field_email !='NULL')  
  190.          {  
  191. /* 检查email是否重复 */
  192. $sql = 'SELECT ' . $this->field_id .  
  193. ' FROM ' .$this->table($this->user_table).  
  194. ' WHERE ' . $this->field_email . ' ='$cfg[email]' '.  
  195. ' AND ' . $this->field_name . ' !='$cfg[post_username]'';  
  196. if ($this->db->getOne($sql, true) > 0)  
  197.                {  
  198. $this->error = ERR_EMAIL_EXISTS;  
  199. return false;  
  200.                }  
  201. // 检查是否为新E-mail
  202. $sql = 'SELECT count(*)' .  
  203. ' FROM ' .$this->table($this->user_table).  
  204. ' WHERE ' . $this->field_email .' = '$cfg[email]' ';  
  205. if($this->db->getOne($sql, true) == 0)  
  206.                {  
  207. // 新的E-mail
  208. $sql = 'UPDATE ' . $GLOBALS['ecs']->table('users'). ' SET is_validated = 0 WHERE user_name = '$cfg[post_username]'';  
  209. $this->db->query($sql);  
  210.                }  
  211. $values[] = $this->field_email . '=''.$cfg['email'] . ''';  
  212.          }  
  213. if (isset($cfg['gender']) && $this->field_gender !='NULL')  
  214.          {  
  215. $values[] = $this->field_gender . '='' .$cfg['gender'] . ''';  
  216.          }  
  217. if ((!empty($cfg['bday'])) && $this->field_bday !='NULL')  
  218.          {  
  219. $values[] = $this->field_bday . '='' .$cfg['bday'] . ''';  
  220.          }  
  221. if ((!is_null($cfg['is_validated'])) &&$this->is_validated != 'NULL')  
  222.          {  
  223. $values[] = $this->is_validated . '='' .$cfg['is_validated'] . ''';  
  224.          }  
  225. if ($values)  
  226.          {  
  227. $sql = 'UPDATE ' .$this->table($this->user_table).  
  228. ' SET ' . implode(', '$values).  
  229. ' WHERE ' . $this->field_name .'='' . $cfg['post_username'] . '' LIMIT 1';  
  230. $this->db->query($sql);  
  231. if ($this->need_sync)  
  232.                {  
  233. if (empty($cfg['md5password']))  
  234.                      {  
  235. $this->sync($cfg['username']);  
  236.                      }  
  237. else
  238.                      {  
  239. $this->sync($cfg['username'], '',$cfg['md5password']);  
  240.                      }  
  241.                }  
  242.          }  
  243. return true;  
  244.     }  
  245. }  
  246. ?>  

【5】修改admin\templates\users_list.htm中的:


  1. <tdalign='center'>{if $user.is_validated} <imgsrcimgsrc='images/yes.gif'> {else} <imgsrcimgsrc='images/no.gif'> {/if}td>

为:


  1. <tdalign='center'><spanonclickspanonclick='listTable.edit(this, 'edit_is_validated', {$user.user_id})'id='is_validated_text'>{if $user.is_validated} <imgsrcimgsrc='images/yes.gif'> {else} <imgsrc='images/no.gif'>{/if}td>span>td>

【6】修改admin\js\listtable.js中的listTable.edit响应函数为:

  • /**
  •  * 创建一个可编辑区
  •  */
  • listTable.edit = function(obj, act, id)  
  • {  
  • var tag =obj.firstChild.tagName;  
  • if (typeof(tag) !='undefined' && tag.toLowerCase() == 'input')  
  •   {  
  • return;  
  •   }  
  • /* 保存原始的内容 */
  • var org = obj.innerHTML;  
  • var val = Browser.isIE ?obj.innerText : obj.textContent;  
  • /* 创建一个输入框 */
  • var txt =document.createElement('INPUT');  
  •   txt.value = (val == 'N/A') ?'' : val;  
  •   txt.style.width =(obj.offsetWidth + 12) + 'px' ;  
  • /* 隐藏对象中的内容,并将输入框加入到对象中 */
  •   obj.innerHTML ='';  
  •   obj.appendChild(txt);  
  •   txt.focus();  
  • /* 编辑区输入事件处理函数 */
  •   txt.onkeypress = function(e)  
  •   {  
  • var evt =Utils.fixEvent(e);  
  • var obj = Utils.srcElement(e);  
  • if (evt.keyCode == 13)  
  •     {  
  •       obj.blur();  
  • //www.
  • returnfalse;  
  •     }  
  • if (evt.keyCode == 27)  
  •     {  
  •       obj.parentNode.innerHTML= org;  
  •     }  
  •   }  
  • /* 编辑区失去焦点的处理函数 */
  •   txt.onblur = function(e)  
  •   {  
  • if(Utils.trim(txt.value).length > 0)  
  •     {  
  •       res =Ajax.call(listTable.url, 'act='+act+'&val=' +encodeURIComponent(Utils.trim(txt.value)) + '&id=' +id, null,'POST''JSON'false);  
  • if (res.message)  
  •       {  
  •         alert(res.message);  
  •       }  
  • if(res.id &&(res.act == 'goods_auto' || res.act == 'article_auto'))  
  •       {  
  •          document.getElementById('del'+res.id).innerHTML = '+ thisfile +'?goods_id='+ res.id+'&act=del\' onclick=\'returnconfirm(''+deleteck+'');\'>'+deleteid+'';  
  •       }  
  •       obj.innerHTML =(res.error == 0) ? res.content : org;  
  •     }  
  • else
  •     {  
  •       obj.innerHTML = org;  
  •     }  
  • if (act =='edit_is_validated')  
  •     {  
  • if (obj.innerHTML == '1')  
  •          {  
  •                 obj.innerHTML ='';  
  •          }  
  • else
  •            {  
  •                obj.innerHTML = '';  
  •            }  
  •     }  
  •   }  
  • }  
  • 【7】在admin\users.php中增加:


    1. /*------------------------------------------------------ */
    2. //-- 编辑会员有效性
    3. /*------------------------------------------------------ */
    4. elseif ($_REQUEST['act'] == 'edit_is_validated')  
    5. {  
    6. /* 检查权限 */
    7.      check_authz_json('users_manage');  
    8. $id =empty($_REQUEST['id']) ? 0 : intval($_REQUEST['id']);  
    9. $is_validated =is_null($_REQUEST['val']) ? '' : json_str_iconv(trim($_REQUEST['val']));  
    10. $users =&init_users();  //www.
    11. $sql = 'SELECTuser_name, email FROM ' . $ecs->table('users') . ' WHERE user_id ='$id'';  
    12. $row =$db->GetRow($sql);  
    13. $username =$row['user_name'];  
    14. $email =$row['email'];  
    15. if (($is_validated == '0')|| ($is_validated == 1))  
    16.      {  
    17. if($users->edit_user(array('username'=>$username'email'=>$email,'is_validated'=>$is_validated)))  
    18.            {  
    19.                  admin_log(addslashes($username),'edit''users');  
    20.                  make_json_result(stripcslashes($is_validated));  
    21.            }  
    22. else
    23.            {  
    24. $msg =($users->error == ERR_EMAIL_EXISTS) ? $GLOBALS['_LANG']['email_exists'] :$GLOBALS['_LANG']['edit_user_failed'];  
    25.                  make_json_error($msg);  
    26.            }  
    27.      }  
    28. else
    29.      {  
    30.            make_json_error($GLOBALS['_LANG']['invalid_is_validated']);  
    31.      }  
    32. }  

    【8】user.php中将:

    1. show_message(sprintf($_LANG['register_success'], $username .$ucdata), array($_LANG['back_up_page'], $_LANG['profile_lnk']),array($back_act'user.php'), 'info');  

    改为:

    1. show_message(sprintf($_LANG['register_success'], $username .$ucdata), array($_LANG['back_up_page']), array($back_act), 'info');  

    1. if ($user->check_user($username) || admin_registered($username))  

    改为:


    1. if (($user->check_user($username) != 0) ||admin_registered($username))  

    将:


    1. if ($user->login($username$password,isset($_POST['remember'])))  
    2.     {  
    3.         update_user_info();  
    4.         recalculate_price();  
    5. $ucdata =isset($user->ucdata)? $user->ucdata : '';  
    6.        show_message($_LANG['login_success'] . $ucdata ,array($_LANG['back_up_page'], $_LANG['profile_lnk']),array($back_act,'user.php'), 'info');  
    7.     }  

    改为:


    1. $rt = $user->login($username,$password,isset($_POST['remember']));  
    2. if ($rt > 0)  
    3.     {  
    4.         update_user_info();  
    5.         recalculate_price();  
    6. $ucdata =isset($user->ucdata)? $user->ucdata : '';  
    7.        show_message($_LANG['login_success'] . $ucdata ,array($_LANG['back_up_page'], $_LANG['profile_lnk']),array($back_act,'user.php'), 'info');  
    8.     }  
    9. elseif ($rt == -1)  
    10.     {  
    11.          show_message($_LANG['login_failure_invalid'], $_LANG['relogin_lnk'],'user.php''error');  
    12.     }  

    将:

    1. if ($user->login($username$password))  
    2.     {  
    3.        update_user_info();  //更新用户信息
    4.         recalculate_price();// 重新计算购物车中的商品价格
    5. $smarty->assign('user_info', get_user_info());  
    6. $ucdata =empty($user->ucdata)? '' : $user->ucdata;  
    7. $result['ucdata'] =$ucdata;  
    8. $result['content'] =$smarty->fetch('library/member_info.lbi');  
    9.     }  

    改为:   

    1. $rt =$user->login($username$password);  
    2. if ($rt > 0)  
    3.    {  
    4.        update_user_info();  //更新用户信息
    5.        recalculate_price();// 重新计算购物车中的商品价格
    6. $smarty->assign('user_info', get_user_info());  
    7. $ucdata =empty($user->ucdata)? '' : $user->ucdata;  
    8. $result['ucdata'] =$ucdata;  
    9. $result['content'] =$smarty->fetch('library/member_info.lbi');  
    10.    }  
    11. elseif ($rt == -1) //www.
    12.    {  
    13. if ($_SESSION['login_fail'] > 2)  
    14.         {  
    15. $smarty->assign('enabled_captcha', 1);  
    16. $result['html'] =$smarty->fetch('library/member_info.lbi');  
    17.         }  
    18. $result['error']   = 1;  
    19. $result['content'] = $_LANG['login_failure_invalid'];  
    20.    }'font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);'

    将:

    1. if (($user_info && (!empty($code) &&md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']) ==$code)) || ($_SESSION['user_id']>0 && $_SESSION['user_id'] ==$user_id && $user->check_user($_SESSION['user_name'],$old_password)))  

    改为:

    1. if (($user_info && (!empty($code) &&md5($user_info['user_id'] . $_CFG['hash_code'] . $user_info['reg_time']) ==$code)) || ($_SESSION['user_id']>0 && $_SESSION['user_id'] ==$user_id && ($user->check_user($_SESSION['user_name'],$old_password) > 0)))  

    【9】flow.php中将:


    1. if ($user->login($_POST['username'],$_POST['password'],isset($_POST['remember'])))  
    2.             {  
    3.                update_user_info();  //更新用户信息
    4.                recalculate_price(); // 重新计算购物车中的商品价格
    5. /* 检查购物车中是否有商品 没有商品则跳转到首页 */
    6. $sql ='SELECT COUNT(*) FROM ' . $ecs->table('cart') . ' WHEREsession_id = '' . SESS_ID . '' ';  
    7. if($db->getOne($sql) > 0)  
    8.                 {  
    9.                     ecs_header('Location:flow.php?step=checkout\n');  
    10.                 }  
    11. else
    12.                 {  
    13.                    ecs_header('Location:index.php\n');  
    14.                 }  
    15. exit;  
    16.             }  

    改为:

    1. $rt = $user->login($_POST['username'],$_POST['password'],isset($_POST['remember']));  
    2. if ($rt > 0)  
    3.             {  
    4.                update_user_info();  //更新用户信息
    5.                recalculate_price(); // 重新计算购物车中的商品价格
    6. /* 检查购物车中是否有商品 没有商品则跳转到首页 */
    7. $sql ='SELECT COUNT(*) FROM ' . $ecs->table('cart') . ' WHEREsession_id = '' . SESS_ID . '' ';  
    8. if($db->getOne($sql) > 0)  
    9.                 {  
    10.                    ecs_header('Location: flow.php?step=checkout\n');  
    11.                 }  
    12. else
    13.                 {  
    14.                    ecs_header('Location:index.php\n');  
    15.                 }  
    16. exit;  
    17.             }  
    18. elseif ($rt ==-1)  
    19.             {  
    20.                  show_message($_LANG['login_failure_invalid'],$_LANG['relogin_lnk'], 'user.php''error');  
    21.             }  
    转载请注明网址 http://www./php/ecshop/2029.html(责任编辑:最模板)

      本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
      转藏 分享 献花(0

      0条评论

      发表

      请遵守用户 评论公约

      类似文章 更多