示例#1
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错
     $p_captcha = Utils::filterAlnumStr($p_captcha);
     // 需要跳转回去的地址
     $returnUrl = $validator->validate('returnUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']');
         goto out_fail;
     }
     $userService = new UserService();
     // 检查用户是否已经注册
     $isUserExist = $userService->isUserExist($input['user_name'], $input['email']);
     if ($isUserExist) {
         $this->addFlashMessage($isUserExist . '已经存在');
         goto out_fail;
     }
     // 注册用户
     $user = $userService->registerUser($input);
     if (!$user) {
         $this->addFlashMessage('用户注册失败,请稍后刷新页面重试');
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     $this->addFlashMessage("注册成功");
     if ($returnUrl) {
         header('Location:' . $returnUrl);
         return;
     } else {
         // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
         RouteHelper::jumpBack($this, '/', true);
     }
     return;
     // 这里正常返回
     out_fail:
     // 失败,从这里出口
     $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time())));
     $smarty->display('user_register.tpl', 'User|Register|post');
 }
示例#2
0
文件: Login.php 项目: swcug/bzfshop
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->validate('password');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $adminService = new AdminUserService();
     // 验证用户登陆
     $admin = $adminService->doAuthAdmin($input['user_name'], $input['user_name'], $input['password']);
     if (!$admin) {
         $this->addFlashMessage("登陆失败,用户名、密码错误");
         goto out_fail;
     }
     // 记录用户的登陆信息
     $adminUserInfo = $admin->toArray();
     unset($adminUserInfo['password']);
     // 不要记录密码
     // 取得用户的角色权限
     $adminUserInfo['role_action_list'] = '';
     if ($adminUserInfo['role_id'] > 0) {
         $metaRoleService = new MetaRoleService();
         $role = $metaRoleService->loadRoleById($adminUserInfo['role_id']);
         if (!$role->isEmpty()) {
             // 赋值角色权限
             $adminUserInfo['role_action_list'] = $role['meta_data'];
         }
     }
     AuthHelper::saveAuthUser($adminUserInfo);
     try {
         // 记录用户登录日志
         AdminLog::logAdminOperate('user.login', '用户登录', 'IP:' . $f3->get('IP'));
     } catch (\Exception $e) {
         // do nothing
     }
     $this->addFlashMessage("登陆成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败从这里入口
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
示例#3
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->minLength(2, '用户名最短为2个字符')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->minLength(6, '密码最短为6个非空字符')->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $userService = new UserService();
     // 检查用户是否已经注册
     $isUserExist = $userService->isUserExist($input['user_name'], $input['email']);
     if ($isUserExist) {
         $this->addFlashMessage($isUserExist . '已经存在');
         goto out_fail;
     }
     // 注册用户
     $user = $userService->registerUser($input);
     if (!$user) {
         $this->addFlashMessage('用户注册失败,请稍后刷新页面重试');
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     // 设置用户名在网页显示
     ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
     $this->addFlashMessage("注册成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败,从这里出口
     $smarty->display('user_login.tpl', 'User|Register|post');
 }
示例#4
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->validate('password');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     // 手机输入,输入法经常无故添加空格,我们需要去除所有的空额,防止出错
     $p_captcha = Utils::filterAlnumStr($p_captcha);
     // 需要跳转回去的地址
     $returnUrl = $validator->validate('returnUrl');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage('验证码错误[' . $p_captcha . '][' . $captchaController->getCaptcha() . ']');
         goto out_fail;
     }
     $userService = new UserService();
     // 验证用户登陆
     $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']);
     if (!$user) {
         $this->addFlashMessage("登陆失败,用户名、密码错误");
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     $this->addFlashMessage("登陆成功");
     if ($returnUrl) {
         header('Location:' . $returnUrl);
         return;
     } else {
         // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
         RouteHelper::jumpBack($this, '/', true);
     }
     return;
     // 这里正常返回
     out_fail:
     // 失败从这里出口
     $smarty->assign('captchaUrl', RouteHelper::makeUrl('/Image/Captcha', array('hash' => time())));
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
示例#5
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userService = new UserService();
     $user = $userService->loadUserById($userInfo['user_id']);
     if (!$user) {
         // 非法用户,应该让它自动登陆出去
         $this->addFlashMessage('非法登陆用户');
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$userService->verifyPassword($userInfo['user_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out_fail;
     }
     // 更新数据
     unset($input['oldpassword']);
     $userService->updateUser($user, $input);
     // 更新认证记录
     AuthHelper::removeAuthUser();
     AuthHelper::saveAuthUser($user->toArray());
     $this->addFlashMessage('资料更新成功');
     RouteHelper::reRoute($this, '/My/Profile');
     return;
     // 这里正常返回
     out_fail:
     // 失败返回
     $smarty->display('my_profile.tpl', 'post');
 }
示例#6
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['phone'] = $validator->validate('phone');
     $input['address'] = $validator->validate('address');
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     $authSupplierUser = AuthHelper::getAuthUser();
     $supplierUserService = new SupplierUserService();
     // 验证用户登陆
     $supplierUser = $supplierUserService->loadSupplierById($authSupplierUser['suppliers_id']);
     if ($supplierUser->isEmpty()) {
         $this->addFlashMessage("非法登陆用户");
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$supplierUserService->verifyPassword($authSupplierUser['suppliers_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out;
     }
     // 更新数据
     unset($input['oldpassword']);
     $supplierUserService->updateSupplier($supplierUser, $input);
     // 记录用户的登陆信息
     $supplierUserInfo = $supplierUser->toArray();
     unset($supplierUserInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($supplierUserInfo);
     $this->addFlashMessage("修改资料成功");
     $smarty->assign($supplierUserInfo);
     out:
     // 从这里出去
     $smarty->display('my_profile.tpl');
 }
示例#7
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_name'] = $validator->required('用户名不能为空')->validate('user_name');
     $input['password'] = $validator->required('密码不能为空')->validate('password');
     $p_captcha = $validator->required('验证码不能为空')->validate('captcha');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 检查验证码是否有效
     $captchaController = new \Controller\Image\Captcha();
     if (!$captchaController->validateCaptcha($p_captcha)) {
         $this->addFlashMessage("验证码错误");
         goto out_fail;
     }
     $userService = new UserService();
     // 验证用户登陆
     $user = $userService->doAuthUser($input['user_name'], $input['user_name'], $input['password']);
     if (!$user) {
         $this->addFlashMessage("登陆失败,用户名、密码错误");
         goto out_fail;
     }
     // 记录用户的登陆信息
     $userInfo = $user->toArray();
     unset($userInfo['password']);
     // 不要记录密码
     AuthHelper::saveAuthUser($userInfo, 'normal');
     // 设置用户名在网页显示
     ClientData::saveClientData(Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(Login::$clientDataUserNameDisplayKey, $user->user_name);
     $this->addFlashMessage("登陆成功");
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
     return;
     // 这里正常返回
     out_fail:
     // 失败从这里入口
     $smarty->display('user_login.tpl', 'User|Login|post');
 }
示例#8
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['user_real_name'] = $validator->required('管理员名称不能为空')->validate('user_real_name');
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     $input['user_desc'] = $validator->validate('user_desc');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
         if ($f3->get('sysConfig[is_demo]')) {
             $this->addFlashMessage('演示系统不允许修改密码');
             goto out;
         }
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     $authAdminUser = AuthHelper::getAuthUser();
     $adminUserService = new AdminUserService();
     // 验证用户登陆
     $adminUser = $adminUserService->loadAdminById($authAdminUser['user_id']);
     if ($adminUser->isEmpty()) {
         $this->addFlashMessage("非法登陆用户");
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$adminUserService->verifyPassword($authAdminUser['user_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out;
     }
     // 更新数据
     unset($input['oldpassword']);
     $adminUserService->updateAdmin($adminUser, $input);
     // 记录用户的登陆信息
     $adminUserInfo = $adminUser->toArray();
     unset($adminUserInfo['password']);
     // 不要记录密码
     // 取得用户的角色权限
     $adminUserInfo['role_action_list'] = '';
     if ($adminUserInfo['role_id'] > 0) {
         $metaRoleService = new MetaRoleService();
         $role = $metaRoleService->loadRoleById($adminUserInfo['role_id']);
         if (!$role->isEmpty()) {
             // 赋值角色权限
             $adminUserInfo['role_action_list'] = $role['meta_data'];
         }
     }
     AuthHelper::saveAuthUser($adminUserInfo);
     $this->addFlashMessage("修改资料成功");
     $smarty->assign($adminUserInfo);
     out:
     // 从这里出去
     $smarty->display('my_profile.tpl');
 }
示例#9
0
 public function post($f3)
 {
     //首先验证参数签名
     $map = $_POST;
     unset($map['Vkey']);
     //读取除了vkey外的所有参数,并且放入数组map中
     ksort($map);
     //进行按参数的升序排序
     //进行签名,注意考虑到md5加密输出的大小写问题,所有约定md5的输出均为小写
     $vkey = implode('', array_values($map));
     $md5_1 = strtolower(md5($vkey . YiqifaCpsPlugin::getOptionValue('qqcaibei_key1')));
     $vkey = strtolower(md5($md5_1 . YiqifaCpsPlugin::getOptionValue('qqcaibei_key2')));
     if ($vkey != $_POST['Vkey']) {
         // 参数签名错误
         goto out;
     }
     // 保存额外的 亿起发 参数
     $orderRefer = array();
     $orderRefer['utm_medium'] = 'QQCAIBEI';
     //设置 cookie
     ReferHelper::setOrderReferSpecific($f3, $orderRefer, YiqifaCpsPlugin::getOptionValue('yiqifacps_duration'));
     $f3->set('SESSION[yiqifa_caibei_order_refer]', ReferHelper::parseOrderRefer($f3));
     // 取得QQ彩贝传递过来的参数
     //$acct     = @$_POST['Acct'];
     $url = @$_POST['Url'];
     $openId = @$_POST['OpenId'];
     //$clubInfo = @intval($_POST['ClubInfo']); // 会员等级信息,目前没用
     $viewInfo = @$_POST['ViewInfo'];
     if (get_magic_quotes_gpc()) {
         $viewInfo = stripslashes($viewInfo);
     }
     $viewInfoArray = array();
     parse_str($viewInfo, $viewInfoArray);
     //解析 viewInfoArray 数组
     //$f3->set('SESSION[qqcaibei_viewinfoarray]', json_encode($viewInfoArray)); //放入到 session 里面
     // 设置 ClientData
     ClientData::saveClientData('qqcaibei_viewinfoarray', json_encode($viewInfoArray));
     if (empty($openId)) {
         // 没有  openId 没法登陆,直接退出
         goto out;
     }
     // 这里做 QQ彩贝 联合登陆
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 之前没有登陆过,自动注册用户
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
     printLog('注册QQ用户:' . print_r($viewInfoArray, true), 'QQLOGIN', \Core\Log\Base::INFO);
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'qqcaibei');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ彩贝用户:' . $viewInfoArray['NickName']);
     out:
     // 页面跳转到商品
     $redirectUrl = empty($url) ? '/' : $url;
     RouteHelper::reRoute($this, $redirectUrl);
     return;
 }
示例#10
0
 /**
  * QQ 登陆
  */
 public function get($f3)
 {
     global $logger;
     global $smarty;
     // 验证 state 参数,防止 csrf 攻击
     if ($_REQUEST['state'] != $f3->get('SESSION[qq_login_state]')) {
         $errorMessage = 'qq login state doest not match, GET[' . $f3->get('GET[state]') . '] SESSION[' . $f3->get('SESSION[qq_login_state]') . ']';
         $logger->addLogInfo(\Core\Log\Base::NOTICE, 'QQLOGIN', $errorMessage);
         goto out;
     }
     // 获取 access_token
     $callback = RouteHelper::makeUrl('/Thirdpart/QQAuth/Callback', null, false, true);
     $tokenUrl = "https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&" . "client_id=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&redirect_uri=" . urlencode($callback) . "&client_secret=" . QQAuthPlugin::getOptionValue('qqauth_appkey') . "&code=" . $_REQUEST["code"];
     $response = $this->get_url_contents($tokenUrl);
     if (strpos($response, "callback") !== false) {
         $lpos = strpos($response, "(");
         $rpos = strrpos($response, ")");
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
         $msg = json_decode($response);
         if (isset($msg->error)) {
             $errorMessage = 'error [' . $msg->error . '] msg [' . $msg->error_description . ']';
             $logger->addLogInfo(\Core\Log\Base::NOTICE, 'QQLOGIN', $errorMessage);
             goto out;
         }
     }
     $params = array();
     parse_str($response, $params);
     $logger->addLogInfo(\Core\Log\Base::DEBUG, 'QQLOGIN', print_r($params, true));
     $accessToken = $params["access_token"];
     // 取得 OpenID
     $graphUrl = "https://graph.qq.com/oauth2.0/me?access_token=" . $accessToken;
     $response = $this->get_url_contents($graphUrl);
     if (strpos($response, "callback") !== false) {
         $lpos = strpos($response, "(");
         $rpos = strrpos($response, ")");
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
     }
     $user = json_decode($response);
     if (isset($user->error)) {
         $errorMessage = 'error [' . $msg->error . '] msg [' . $msg->error_description . ']';
         goto out;
     }
     $openId = $user->openid;
     // 取得 userInfo
     $get_user_info = "https://graph.qq.com/user/get_user_info?" . "access_token=" . $accessToken . "&oauth_consumer_key=" . QQAuthPlugin::getOptionValue('qqauth_appid') . "&openid=" . $openId . "&format=json";
     $response = $this->get_url_contents($get_user_info);
     $qqUserInfo = json_decode($response, true);
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 之前没有登陆过,自动注册用户
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $openId . '@qq.com', $openId . '@qq.com', true);
     $logger->addLogInfo(\Core\Log\Base::INFO, 'QQLOGIN', '注册QQ用户:' . print_r($qqUserInfo, true));
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'qqlogin');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, 'QQ用户:' . $qqUserInfo['nickname']);
     out:
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
 }
示例#11
0
文件: Auth.php 项目: jackycgq/bzfshop
 /**
  * 重新加载用户信息
  */
 public static function reloadAuthUser()
 {
     $authUser = Auth::getAuthUser();
     if (empty($authUser) || !isset($authUser['user_id']) || empty($authUser['user_id'])) {
         return;
     }
     $basicUserService = new UserBasicService();
     $user = $basicUserService->loadUserById($authUser['user_id']);
     if ($user->isEmpty()) {
         return;
     }
     Auth::saveAuthUser($user->toArray());
 }
示例#12
0
 /**
  * 360 登陆
  */
 public function get($f3)
 {
     global $logger;
     if (empty($_GET['code'])) {
         $this->addFlashMessage('360联合登陆失败,Code 不存在');
         goto out;
     }
     require_once 'sdk/QClient.php';
     // 获取access token
     $callback = RouteHelper::makeUrl('/Thirdpart/Dev360Auth/Callback', null, false, true);
     $oauth = new \QOAuth2(Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_secrect'), '');
     $token = $oauth->getAccessTokenByCode($_GET['code'], $callback);
     if (empty($token['access_token'])) {
         $this->addFlashMessage('360联合登陆失败,获取 access_token 失败');
         goto out;
     }
     // 调用API,获取用户信息
     $client = new \QClient(Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_key'), Dev360AuthPlugin::getOptionValue(self::$optionKeyPrefix . 'dev360auth_app_secrect'), $token['access_token']);
     $user = $client->userMe();
     if (empty($user)) {
         $this->addFlashMessage('360联合登陆失败,用户信息为空');
         goto out;
     }
     $param = array('user_id' => $user['id'], 'username' => !empty($user['name']) ? (string) $user['name'] : '网友', 'token' => $token['access_token']);
     // put all values into $_POST[]
     $qid = $param['user_id'];
     $qname = urldecode($param['username']);
     $qmail = '';
     if (empty($qid)) {
         // 没有 qid 没法登陆
         $this->addFlashMessage('360联合登陆失败,没有 qid');
         goto out;
     }
     $sns_login = "******";
     // 用户登陆操作
     $userBasicService = new UserBasicService();
     $authUser = $userBasicService->doAuthSnsUser($sns_login, null, null, false);
     if ($authUser) {
         goto out_login_user;
     }
     // 用户不存在,自动注册一个用户
     if (empty($qmail)) {
         $qmail = '' . $qid . '@360.cn';
     }
     if (empty($qname)) {
         $qname = $qmail;
     }
     $retry = 10;
     // 重试 10 次
     $regUserName = $qname;
     while ($userBasicService->isUserExist($regUserName, null) && $retry-- > 0) {
         $regUserName = $qname . '_' . rand(10000, 99999);
     }
     if ($retry <= 0) {
         $this->addFlashMessage('360联合登陆失败,用户名已经存在,无法自动注册');
         goto out;
     }
     $authUser = $userBasicService->doAuthSnsUser($sns_login, $qname, $qmail, true);
     $logger->addLogInfo(\Core\Log\Base::INFO, 'DEV360AUTH', '注册360用户' . print_r(array('sns_login' => $sns_login, 'qname' => $qname, 'qmail' => $qmail), true));
     out_login_user:
     AuthHelper::saveAuthUser($authUser->toArray(), 'dev360auth');
     // 设置用户名在网页显示
     ClientData::saveClientData(\Controller\User\Login::$clientDataIsUserLoginKey, true);
     ClientData::saveClientData(\Controller\User\Login::$clientDataUserNameDisplayKey, '360用户:' . $authUser['user_name']);
     out:
     // 跳转到用户之前看的页面,如果之前没有看过的页面那就回到首页
     RouteHelper::jumpBack($this, '/', true);
 }