Exemplo n.º 1
0
 public function chooseAction(Request $request, $type)
 {
     $token = $request->getSession()->get('oauth_token');
     $client = $this->createOAuthClient($type);
     $clientMetas = OAuthClientFactory::clients();
     $clientMeta = $clientMetas[$type];
     try {
         $oauthUser = $client->getUserInfo($token);
     } catch (\Exception $e) {
         $message = $e->getMessage();
         if ($message == 'unaudited') {
             $message = '抱歉!暂时无法通过第三方帐号登录。原因:' . $clientMeta['name'] . '登录连接的审核还未通过。';
         } else {
             $message = '抱歉!暂时无法通过第三方帐号登录。原因:' . $message;
         }
         $this->setFlashMessage('danger', $message);
         return $this->redirect($this->generateUrl('login'));
     }
     return $this->render('TopxiaWebBundle:Login:bind-choose.html.twig', array('oauthUser' => $oauthUser, 'type' => $type, 'clientMeta' => $clientMeta, 'hasPartnerAuth' => $this->getAuthService()->hasPartnerAuth()));
 }
Exemplo n.º 2
0
 public function loginConnectAction(Request $request)
 {
     $loginConnect = $this->getSettingService()->get('login_bind', array());
     $default = array('login_limit' => 0, 'enabled' => 0, 'verify_code' => '', 'captcha_enabled' => 0, 'temporary_lock_enabled' => 0, 'temporary_lock_allowed_times' => 5, 'ip_temporary_lock_allowed_times' => 20, 'temporary_lock_minutes' => 20);
     $clients = OAuthClientFactory::clients();
     foreach ($clients as $type => $client) {
         $default["{$type}_enabled"] = 0;
         $default["{$type}_key"] = '';
         $default["{$type}_secret"] = '';
         $default["{$type}_set_fill_account"] = 0;
     }
     $loginConnect = array_merge($default, $loginConnect);
     if ($request->getMethod() == 'POST') {
         $loginConnect = $request->request->all();
         $this->getSettingService()->set('login_bind', $loginConnect);
         $this->getLogService()->info('system', 'update_settings', "更新登录设置", $loginConnect);
         $this->setFlashMessage('success', '登录设置已保存!');
     }
     return $this->render('TopxiaAdminBundle:System:login-connect.html.twig', array('loginConnect' => $loginConnect, 'clients' => $clients));
 }
Exemplo n.º 3
0
 protected function checkBindsName($type)
 {
     $types = array_keys(OAuthClientFactory::clients());
     if (!in_array($type, $types)) {
         throw new NotFoundHttpException();
     }
 }
Exemplo n.º 4
0
 public function bindUser($type, $fromId, $toId, $token)
 {
     $user = $this->getUserDao()->getUser($toId);
     if (empty($user)) {
         throw $this->createServiceException('用户不存在,第三方绑定失败');
     }
     $types = array_keys(OAuthClientFactory::clients());
     $types = array_merge($types, array('discuz', 'phpwind'));
     if (!in_array($type, $types)) {
         throw $this->createServiceException("{$type}类型不正确,第三方绑定失败。");
     }
     if ($type == 'weixinweb' || $type == 'weixinmob') {
         $type = 'weixin';
     }
     return $this->getUserBindDao()->addBind(array('type' => $type, 'fromId' => $fromId, 'toId' => $toId, 'token' => empty($token['token']) ? '' : $token['token'], 'createdTime' => time(), 'expiredTime' => empty($token['expiredTime']) ? 0 : $token['expiredTime']));
 }
Exemplo n.º 5
0
 public function oauth2LoginsBlockAction($targetPath, $displayName = true)
 {
     $clients = OAuthClientFactory::clients();
     return $this->render('TopxiaWebBundle:Login:oauth2-logins-block.html.twig', array('clients' => $clients, 'targetPath' => $targetPath, 'displayName' => $displayName));
 }