/** * 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; }
/** * processGithub * * @param \Hybrid_Provider_Adapter $adapter * @param Credential $credential * * @return Credential */ protected function processGitHub(\Hybrid_Provider_Adapter $adapter, Credential $credential) { $userProfile = $adapter->getUserProfile(); $loginName = $this->warder->getLoginName(); // Generate a temp username that usr can edit it later. if ($loginName != 'email') { $username = strtolower(str_replace(' ', '', $userProfile->displayName)) . '-' . $userProfile->identifier; $credential->{$loginName} = $username; } $credential->email = $userProfile->email; $credential->name = $userProfile->displayName; $credential->_loginName = 'email'; return $credential; }
/** * @return \Hybrid_User_Profile */ public function getProfile() { return $this->authAdapter->getUserProfile(); }
/** * Things to do AFTER connected. * Extend this class then overwrite this method to implement your own logic * * @param Request $request * @param \Hybrid_Provider_Adapter $adapter */ protected function postProcess(Request $request, \Hybrid_Provider_Adapter $adapter) { $user = $adapter->getUserProfile(); print_r($user); die; }