Esempio n. 1
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));
 }
Esempio n. 2
0
 protected function createOAuthClient($type)
 {
     $settings = $this->setting('login_bind');
     if (empty($settings)) {
         throw new \RuntimeException('第三方登录系统参数尚未配置,请先配置。');
     }
     if (empty($settings) || !isset($settings[$type . '_enabled']) || empty($settings[$type . '_key']) || empty($settings[$type . '_secret'])) {
         throw new \RuntimeException("第三方登录({$type})系统参数尚未配置,请先配置。");
     }
     if (!$settings[$type . '_enabled']) {
         throw new \RuntimeException("第三方登录({$type})未开启");
     }
     $config = array('key' => $settings[$type . '_key'], 'secret' => $settings[$type . '_secret']);
     $client = OAuthClientFactory::create($type, $config);
     return $client;
 }
Esempio n. 3
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']));
 }
Esempio n. 4
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));
 }