本文整理汇总了PHP中UserIdentity::setState方法的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity::setState方法的具体用法?PHP UserIdentity::setState怎么用?PHP UserIdentity::setState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserIdentity
的用法示例。
在下文中一共展示了UserIdentity::setState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
/**
* This is login function
*
* @param string $sessionId
* @param string $username
* @param string $auth
* @return array
*/
public function login($sessionId, $username, $auth)
{
$timeout = time();
$session = Yii::app()->getSession();
$session->close();
$session->setSessionID($sessionId);
$session->open();
$code = API::ERROR_USER_AUTH_FAILED;
$info = Yii::t('API', 'user authenticate failed error info');
$rand = $session->get(API::API_RAND_KEY);
$user = TestUser::model()->findByAttributes(array('username' => $username));
if (null !== $user) {
if ($auth == $this->encrypt($username, $user->password, $rand)) {
$code = API::ERROR_NONE;
$info = '';
$identity = new UserIdentity($username, $user->password);
$identity->errorCode = UserIdentity::ERROR_NONE;
$identity->setState('id', $user->id);
$identity->setState('username', $username);
Yii::app()->user->login($identity, 0);
$timeout += $session->getTimeout();
LoginService::setUserInfo();
/*
* CWebUser::login() function will call sesssion_regenrate_id() function
* I dont konw why to do that right now and store the data to old session
*/
$data = $_SESSION;
$session->close();
$session->setSessionID($sessionId);
$session->open();
foreach ($data as $key => $val) {
$_SESSION[$key] = $val;
}
}
}
return array($code, $info, $timeout);
}
示例2: login
public function login()
{
$identity = new UserIdentity($this->login, $this->ls_id, $this->gs_id);
$identity->authenticate();
switch ($identity->errorCode) {
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('status', Yii::t('main', 'Неправильный Логин или Пароль.'));
break;
case UserIdentity::ERROR_STATUS_INACTIVE:
$this->addError('status', Yii::t('main', 'Аккаунт не активирован.'));
break;
case UserIdentity::ERROR_STATUS_BANNED:
$this->addError('status', Yii::t('main', 'Аккаунт заблокирован.'));
break;
case UserIdentity::ERROR_STATUS_IP_NO_ACCESS:
$this->addError('status', Yii::t('main', 'С Вашего IP нельзя зайти на аккаунт.'));
break;
case UserIdentity::ERROR_NONE:
$identity->setState('gs_id', $this->gs_id);
$this->clearBadAttempt();
$duration = 3600 * 24 * 7;
// 7 days
user()->login($identity, $duration);
return TRUE;
}
return FALSE;
}