isUserConnected() public method

Return true if the user is connected to the current provider
public isUserConnected ( ) : boolean
return boolean
 /**
  * Authenticates a user.
  * @throws Exception
  * @return boolean whether authentication succeeds.
  */
 public function authenticate()
 {
     $params = array();
     if (strtolower($this->provider) == 'openid') {
         $params['openid_identifier'] = $_GET['openid_identifier'];
     }
     $this->_hybridProviderAdapter = $this->hybridAuth->authenticate($this->provider, $params);
     if (!$this->_hybridProviderAdapter->isUserConnected()) {
         $this->errorCode = self::ERROR_PASSWORD_INVALID;
         return false;
     }
     /** @var AccountModule $account */
     $account = Yii::app()->getModule('account');
     $userHybridAuth = CActiveRecord::model($account->userHybridAuthClass)->findByAttributes(array($account->providerField => $this->provider, $account->identifierField => $this->_hybridProviderAdapter->getUserProfile()->identifier));
     /** @var AccountUser $user */
     $user = $userHybridAuth ? CActiveRecord::model($account->userClass)->findByPk($userHybridAuth->user_id) : false;
     if (!$user) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
         return false;
     }
     $this->_id = $user->primaryKey;
     if ($account->activatedField && !$user->{$account->activatedField}) {
         $this->errorCode = self::ERROR_NOT_ACTIVATED;
         return false;
     }
     if ($account->disabledField && $user->{$account->disabledField}) {
         $this->errorCode = self::ERROR_DISABLED;
         return false;
     }
     $this->_id = $user->id;
     $this->_hybridProviderAdapter = $this->_hybridProviderAdapter;
     $this->errorCode = self::ERROR_NONE;
     return true;
 }
Example #2
0
 /**
  * @return \Hybrid_Provider_Adapter
  * @throws \Exception
  */
 public function getAuthAdapter()
 {
     if (!$this->authAdapter) {
         /** @var \Hybrid_Provider_Adapter $authProvider */
         $this->authAdapter = $this->getHybridauth()->authenticate($this->providerName);
         if (!$this->authAdapter->isUserConnected()) {
             throw new \Exception('Cannot connect to current provider !');
         }
     }
     return $this->authAdapter;
 }