コード例 #1
0
 /**
  * Action NologinResetPassword
  */
 public function actionNologinResetPassword()
 {
     $util = Yii::$app->util;
     $request = Yii::$app->getRequest();
     $session = Yii::$app->session;
     $mUserBase = new UserBaseInfo();
     $params = $request->post();
     $params = array_map('trim', $params);
     $params = array_map('htmlEntityString', $params);
     $route = trim($util->routeDecrypt($params['ca']));
     $tool = $session[$route . '_tool'];
     if (!$route) {
         $util->formatResData(1301, 'illegal_ca', ['msg' => '非法请求']);
     }
     $curStep = StepFlow::getCurStep($route);
     $curStepConfig = StepFlow::getStepConfig($curStep, $route);
     if (!$curStepConfig) {
         $util->formatResData(1301, 'error_config', ['msg' => '非法请求']);
     }
     $password = $params['password'];
     $repassword = $params['repassword'];
     if (empty($password)) {
         $util->formatResData(1501, 'error_password_empty', ['msg' => '密码不能为空']);
     }
     if (empty($repassword)) {
         $util->formatResData(1502, 'error_repassword_empty', ['msg' => '密码确认不能为空']);
     }
     $rePasswd = "/((?=.*\\d)(?=.*\\D)|(?=.*[a-zA-Z])(?=.*[^a-zA-Z]))^.{8,16}\$/";
     $space = '/\\s/';
     if (preg_match($space, $password)) {
         $util->formatResData(1110, 'error_password_space', ['msg' => '密码不能包含空格']);
     }
     if (!preg_match($rePasswd, $password)) {
         $util->formatResData(1407, 'error_password_format', ['msg' => '密码格式不正确']);
     }
     if ($password !== $repassword) {
         $util->formatResData(1602, 'error_inconformity_password', ['msg' => '两次密码输入不一致']);
     }
     try {
         $mUtpl = new UserThirdPartyLogin();
         $user = $mUserBase->getByMobileOrEmail($tool);
         $tplType = $session['tpl_user']['tp_user']['type'];
         $data = $mUtpl->checkBindByUAT($user['id'], UserThirdPartyLogin::BIND_WEB_CHANNEL, $tplType, true);
         if ($data) {
             $origTplUser = json_decode($data['profile_info'], true);
             $origTplUser['open_id'] = $data['open_id'];
             $session['orig_tpl_user'] = $origTplUser;
         }
         if ($user) {
             $result = $mUserBase->updatePassword($user['id'], $password);
             $content = '';
             if ($result) {
                 $data = $result;
                 $data['open_id'] = $user['open_id'];
                 try {
                     $sso = Yii::$app->sso;
                     $res = $sso->sync('password', $data);
                     $sso->syncProfileLog($res, json_encode($data), 'password');
                 } catch (\Exception $e) {
                     $util->formatResData(3000, 'error_system_busy', ['msg' => '系统繁忙,请稍后重试']);
                 }
                 if (isset($curStepConfig['next_step_tpl']) && $curStepConfig['next_step_tpl']) {
                     try {
                         $content = $this->renderAjax($curStepConfig['next_step_tpl'], ['config' => $curStepConfig, 'tool' => $tool, 'route' => $route]);
                     } catch (\Exception $e) {
                         // TODO: 对存在模板情况进行处理
                     }
                 }
                 $util->formatResData(0, 'success', ['content' => $content]);
             } else {
                 Yii::$app->util->formatResData(1300, 'error_register', '重置密码失败');
             }
         } else {
             $util->formatResData(1600, 'error_user_noexists', ['msg' => '重置失败']);
         }
     } catch (\Exception $e) {
         // TODO: 增加日志记录
         $util->formatResData(1, 'error_update_password', ['msg' => '重置失败']);
     }
 }