cwebuser 更新cookie的问题 [ 新手入门 ]
怎么样才可以做到更新用户的信息的时候进行cookie更新
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
public $email;
public $id;
public $phone;
public $record;
public $userInfo;
//accounts
const ERROR_ACCOUNTS=3;
public function __construct($record,$password)
{
$this->record = $record;
$this->password = $password;
}
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
public function authenticate($user = null)
{
/**
* 进行验证
*/
if(empty($user))
{
/**
* 判断用户输入类型
*/
$result = new CEmailValidator();
if ( $result->validateValue($this->record) ){
$this->email = $this->record;
$factor['email'] = $this->record;
} elseif (is_numeric($this->record) ) {
$this->phone = $this->record;
$factor['phone'] = $this->record;
} else {
$this->username = $this->record;
$factor['username'] = $this->record;
}
$user = User::model()->findByAttributes($factor);
$isset = true;
}
if(empty($user))
{
$this->errorCode=self::ERROR_USERNAME_INVALID;
} else if($user->password != $user->encrypt($this->password) && isset($isset)) {
$temp = $user->encrypt($this->password);
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->id = $user->id;
$this->email = $user->email;
$this->username = $user->username;
$this->phone = $user->phone;
$this->userInfo = @$user->userInfo->attributes;
$this->setState('userInfo',$this->userInfo);//用户的相关信息存储到cookie中
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->id;
}
}
<?php
/**
* Created by JetBrains PhpStorm.
* User: Administrator
* Date: 12-10-29
* Time: 下午3:10
* To change this template use File | Settings | File Templates.
*/
class WebUser extends CWebUser
{
public function login($identity,$duration=0)
{
if(parent::login($identity,$duration))
{
$this->updateStates((array)$identity);
return true;
} else {
return false;
}
}
/**
* @param $arr
* 更新SESSION信息
*/
public function updateStates($arr)
{
$this->loadIdentityStates($arr);
}
}
共 1 条回复
-
cookie的使用方法请看
http://www.yiichina.com/topic/85
qq277049
注册时间:2011-12-11
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱10
- 威望0
- 积分10