コード例 #1
0
ファイル: AuthController.php プロジェクト: nidzix/Newscoop
 public function socialAction()
 {
     // hack to import all GLOBAL_HYBRID_ into global namespace
     foreach (token_get_all(file_get_contents(APPLICATION_PATH . '/../hybridauth/hybridauth.php')) as $token) {
         if ($token[0] == T_VARIABLE) {
             $var = substr($token[1], 1);
             if (strstr($var, 'GLOBAL_HYBRID_AUTH_') !== FALSE) {
                 global ${$var};
             }
         }
     }
     require_once APPLICATION_PATH . '/../hybridauth/hybridauth.php';
     $hauth = new Hybrid_Auth();
     if ($hauth->hasError()) {
         var_dump($hauth->getErrorMessage());
         exit;
     }
     if (!$hauth->hasSession()) {
         $adapter = $hauth->setup($this->_getParam('provider'), array('hauth_return_to' => 'http:///auth/social/provider/' . $this->_getParam('provider')));
         $adapter->login();
     } else {
         $adapter = $hauth->wakeup();
         $userData = $adapter->user();
         $adapter = $this->_helper->service('auth.adapter.social');
         $adapter->setProvider($userData->providerId)->setProviderUserId($userData->providerUID);
         $result = $this->auth->authenticate($adapter);
         if ($result->getCode() == Zend_Auth_Result::SUCCESS) {
             $this->_helper->redirector('index', 'dashboard');
         }
         $this->_forward('social', 'register', 'default', array('userData' => $userData));
     }
 }