本文整理匯總了PHP中UserIdentity::autoAuthenticate方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserIdentity::autoAuthenticate方法的具體用法?PHP UserIdentity::autoAuthenticate怎麽用?PHP UserIdentity::autoAuthenticate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類UserIdentity
的用法示例。
在下文中一共展示了UserIdentity::autoAuthenticate方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: activateUser
public function activateUser($token)
{
$transaction = Yii::app()->db->beginTransaction();
try {
$tokenModel = $this->tokenStorage->get($token, UserToken::TYPE_ACTIVATE);
if (null === $tokenModel) {
return false;
}
$userModel = User::model()->findByPk($tokenModel->user_id);
if (null === $userModel) {
return false;
}
$userModel->status = User::STATUS_ACTIVE;
$userModel->email_confirm = User::EMAIL_CONFIRM_YES;
if ($this->tokenStorage->activate($tokenModel) && $userModel->save()) {
// Автоматическая авторизация
$identity = new UserIdentity($userModel->email, $userModel->hash);
if ($identity->autoAuthenticate()) {
Yii::app()->user->login($identity);
}
// Записываем информацию о событии в лог-файл:
Yii::log(Yii::t('UserModule.user', 'Account with activate_key = {activate_key} was activated!', array('{activate_key}' => $token)), CLogger::LEVEL_INFO, UserModule::$logCategory);
$transaction->commit();
return true;
}
throw new CException(Yii::t('UserModule.user', 'There was a problem with the activation of the account. Please refer to the site\'s administration.'));
} catch (Exception $e) {
$transaction->rollback();
return false;
}
}