Beispiel #1
0
 /**
  * 忘记密码通过手机验证码重置新密码处理(支持 ajax).
  * status: 0:用户名, 1:手机号, 2:密码, 3:未在规定时间内设置新密码, 8: 设置失败, 9:设置成功
  *
  * @access public
  * @return void
  * @author Liuping <*****@*****.**>
  */
 public function forgotPasswdByPhoneAction()
 {
     $lang = LANG_SET;
     $username = I('post.username', '');
     $username = authcode($username, 'DECODE', C('AUTH_KEY'));
     $prefix = I('post.prefix', '');
     $prefix = authcode($prefix, 'DECODE', C('AUTH_KEY'));
     $phone = I('post.phone', '');
     $phone = authcode($phone, 'DECODE', C('AUTH_KEY'));
     $passwd = I('post.passwd', '');
     $repasswd = I('post.repasswd', '');
     $newphone = $this->processMobile($prefix, $phone);
     // 校验该用户是否有重置密码记录
     $logModel = new UserResetpwdLogModel();
     $model = new UserModel();
     $userInfo = $model->checkUserAndTel($username, $prefix, $phone);
     if (empty($username)) {
         $result['status'] = 0;
         $result['msg'] = L('CONTROLLER_MSG25');
     } elseif (empty($phone)) {
         $result['status'] = 1;
         $result['msg'] = L('CONTROLLER_MSG8');
     } elseif (!preg_match('/^\\d{7,}$/', $phone)) {
         $result['status'] = 1;
         $result['msg'] = L('CONTROLLER_MSG9');
     } elseif (empty($passwd) || empty($repasswd)) {
         $result['status'] = 2;
         $result['msg'] = L('CONTROLLER_MSG1');
     } elseif ($passwd != $repasswd) {
         $result['status'] = 2;
         $result['msg'] = L('CONTROLLER_MSG15');
     } elseif (!preg_match('/^.{6,20}$/', $passwd)) {
         $result['status'] = 2;
         $result['msg'] = L('CONTROLLER_MSG16');
     } elseif (!$userInfo) {
         $result['status'] = 1;
         $result['msg'] = L('CONTROLLER_MSG22');
     } elseif (!$logModel->checkPhone($username, $newphone)) {
         $result['status'] = 3;
         $result['msg'] = L('CONTROLLER_MSG33');
     } else {
         if ($model->resetPasswd($username, $passwd)) {
             if ($this->isLogin()) {
                 $this->logout();
             }
             // 重置密码成功后, 设置为登录状态
             $this->writeUserInfo($userInfo);
             $result['status'] = 9;
             $result['msg'] = L('CONTROLLER_MSG34');
             $result['url'] = U('Home/Index/index');
         } else {
             $result['status'] = 8;
             $result['msg'] = L('CONTROLLER_MSG49');
         }
     }
     if (IS_AJAX) {
         $this->ajaxReturn($result, 'json');
     } elseif ($result['status'] == 9) {
         //$this->success($result['msg'], $result['url']);
         $this->assign('jumpUrl', $result['url']);
         $this->display('successResetPwd');
     } else {
         $this->error($result['msg']);
     }
 }