修改ECSHOP注册只需要email,并且使用email作为账号
现在很多主流的电商网站都直接用email作为会员账号,好处是省得用户既要想一个用户名,又要填邮箱,邮箱对于电商网站的重要性不用多提,因此用email作为会员的唯一标识是很合理的做法,本文给出针对ECSHOP实现该功能的方法,原理是注册时将email表单的值顺便返回给username,并去掉注册时username的js验证,然后在登录中实现username跟email都可以登录,这样做的好处是,即实现了ecshop用email注册登录的功能,又不改动ecshop的数据库和后台功能,其实本质上没有变化什么,会员账号还是存在的,邮箱也是存在的,只是我们强制把会员账号等于email账号。
首先修改注册部分
————————————————————————————————————————-
1,themes/****/user_passport.dwt 会员名称输入的表单,将之去掉
2,js/user.js 找到 function register() 并将以下代码删除
1 2 3 4 5 6 7 8 9 10 11 12 | 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'; } |
3,user.php 找到 elseif ($action == ‘act_register’) 将以下代码
1 | $username = isset($_POST['username']) ? trim($_POST['username']) : ''; |
改为
1 | $username = isset($_POST['email']) ? trim($_POST['email']) : ''; |
其次实现登录时可以使用email登录
————————————————————————————————————————-
1,includes/modules/integrates/integrate.php 找到 function login 并将整个函数改为以下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | function login($username, $password, $remember = null) { if(is_email($username)) { $sql = "select ".$this->field_name." from ".$this->table($this->user_table)." where ".$this->field_email."='".$username."'"; $username = $this->db->getOne($sql); if(!$username) return false; } if ($this->check_user($username, $password) > 0) { if ($this->need_sync) { $this->sync($username,$password); } $this->set_session($username); $this->set_cookie($username, $remember); return true; } else { return false; } } |
浅唱6(微信/QQ号:909912499),欢迎分享本文,转载请保留出处!部分内容来自网络,如有侵权请联系删除处理!
本站提供代码修改,dedecms,WordPress仿站二次开发 / PHP网站建设以及SEO优化等网络营销推广等服务。
如有需要请加QQ: 909912499