shopnc手机版与UCenter同步,实现手机注册也可以电脑登录
比较久之前解决了shopnc系统与ucenter整合,实现了shopnc注册后,会员可登录ucenter其他应用。
后来应用起来发现,shopnc手机版注册后,电脑无法登陆。检查发现,shopnc手机版注册后,只是向shopnc的member数据表中插入了数据,并没有像ucenter的member表插入数据。
而电脑版登录的时候,其实是从ucenter的member表中读数据,所以就会出现无法登陆的情况。
原因是这样的:手机注册是mobile/control/login.php文件,注册部分并没有像ucenter插入数据。
默认是这样的:
/** * 注册 */ public function registerOp(){ $model_member = Model('member'); $register_info = array(); $register_info['username'] = $_POST['username']; $register_info['password'] = $_POST['password']; $register_info['password_confirm'] = $_POST['password_confirm']; $register_info['email'] = $_POST['email']; $member_info = $model_member->register($register_info); if(!isset($member_info['error'])) { $token = $this->_get_token($member_info['member_id'], $member_info['member_name'], $_POST['client']); if($token) { output_data(array('username' => $member_info['member_name'], 'key' => $token)); } else { output_error('注册失败'); } } else { output_error($member_info['error']); } }
修改如下:
/** * 注册 */ public function registerOp(){ $model_member = Model('member'); if(C('ucenter_status')) { $model_ucenter = Model('ucenter'); $uid = $model_ucenter->addUser(trim($_POST['username']),trim($_POST['password']),trim($_POST['email'])); if($uid<1) showMessage($lang['login_usersave_regist_fail'],'','html','error'); $register_info['member_id'] = $uid; } $register_info = array(); $register_info['username'] = $_POST['username']; $register_info['password'] = $_POST['password']; $register_info['password_confirm'] = $_POST['password_confirm']; $register_info['email'] = $_POST['email']; $member_info = $model_member->register($register_info); if(!isset($member_info['error'])) { $token = $this->_get_token($member_info['member_id'], $member_info['member_name'], $_POST['client']); if($token) { output_data(array('username' => $member_info['member_name'], 'key' => $token)); } else { output_error('注册失败'); } } else { output_error($member_info['error']); } }
需要注意的是:手机注册表单和电脑注册表单,字段名不一样,电脑端字段名是user_name 手机端是username。 所以最开始的时候这里出了点问题
<< 上一篇
下一篇 >>