本文整理汇总了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;
}
}