我们在 /rpotected/components/UserIdentity.php 中有以下函数:
public function authenticate()
{
$username = $this->username;
$password = $this->password;
$user = Users::model()->find('username=? AND password=?', array($username, $password));
if($user === NULL){
$this->errorCode=self::ERROR_UNKNOWN_IDENTITY;
}else{
$this->username = $user->username;
sess('SESS_USER_INFO', $user->attributes);
//print_r(sess('SESS_USER_INFO'));
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}
这是来自 /protected/models/Users.php 的片段:
public function login()
{
if($this->_identity===null)
{
$username = $this->username;
$password = md5($this->password);
//echo "Username: ".$username."<br />Password:".$password;
$this->_identity=new UserIdentity($username, $password);
$this->_identity->authenticate();
}
if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
{
$duration=$this->rememberMe ? 3600*24*30 : 60*20; // 30 days
//print_r($this->_identity);
Yii::app()->user->login($this->_identity,$duration);
//echo "Login Successful";
return true;
}
else{
//echo "Error";
$this->addError('password','Incorrect username or password.');
return false;
}
问题:登录后,单击“我的个人资料”链接会提示再次登录。因此,会话似乎没有存储/保存登录凭据并在登录生命周期内携带它们。
应该如何修改身份验证功能,以便存储会话信息并结转登录凭据?