public function getUserBindInfo($username, $type, $openId) { $third = new UserThirdPartyLogin(); $channel = UserThirdPartyLogin::BIND_API_CHANNEL; if (!$username) { return responseArray(1101, 'username_pwd_params_missing', '用户标识丢失'); } if (!$type) { return responseArray(1201, 'third_type_not_found', '第三方类型不能为空'); } if (!$openId) { return responseArray(1202, 'third_openId_not_found', '第三方账号关联open_id丢失'); } $user = UserBaseInfo::find()->where(['mobile' => $username])->orWhere(['email' => $username])->one(); $userOpenId['open_id'] = $user['open_id']; if ($user == null) { return responseArray(1102, 'user_not_exists', '用户不存在'); } $info = $third->checkBindByUAT($user['id'], $channel, $type, true); $beenBind = $third->checkBeenBindUAT($user['id'], $channel, $type, true); if ($info && is_array($info) || $beenBind) { if ($beenBind['open_id'] == $openId) { return responseArray(0, 'success', '用户已绑定并与现操作绑定号一致', $beenBind['open_id']); } $beenBind['profile_info'] = json_decode($beenBind['profile_info']); $oldBind = []; if (isset($beenBind['profile_info'])) { foreach ($beenBind['profile_info'] as $key => $value) { $oldBind[$key] = $value; } } $oldBind['open_id'] = $beenBind['open_id']; return responseArray(1401, 'has_been_bind', '用户已绑定但与现操作绑定号不一致', $oldBind); } if (!is_array($info)) { return responseArray(1301, 'user_not_bind', '用户未绑定', $user->attributes); } }
/** * 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' => '重置失败']); } }