Yii 还记得我吗
如何在Yii中使用“记住我”功能 我的代码 在Config/Main.php中Yii 还记得我吗,yii,remember-me,Yii,Remember Me,如何在Yii中使用“记住我”功能 我的代码 在Config/Main.php中 'user'=>array( // enable cookie-based authentication 'allowAutoLogin'=>true, ), UserIdentity.php public function authenticate() { $this->errorCode = self::ERROR_NONE; $user
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
UserIdentity.php
public function authenticate() {
$this->errorCode = self::ERROR_NONE;
$user = User::model()->find("username = :username or email=:username", array(":username" => $this->username));
if ($user === null) {
$this->errorCode = self::ERROR_INCORRECT_CREDENTIAL;
} else {
if($user->is_active != 1){
if($user->activation_token_used == 0){
$this->errorCode = self::ERROR_NOT_ACTIVATED;
}
else{
$this->errorCode = self::ERROR_ACCOUNT_INACTIVE;
}
}
else{
$isCorrectPwd = ($user->password !== Yii::app()->mclass->encryptPwd($this->password)) ? false : true;
if ($isCorrectPwd) {
if($user->is_deleted == 1){
$this->errorCode = self::ERROR_ACCOUNT_DELETED;
}
elseif($user->is_active != 1){
if($user->activation_token_used == 0){
$this->errorCode = self::ERROR_NOT_ACTIVATED;
}
else{
$this->errorCode = self::ERROR_ACCOUNT_INACTIVE;
}
}
} else {
$this->errorCode = self::ERROR_INCORRECT_CREDENTIAL;
}
}
}
if ($this->errorCode == self::ERROR_NONE) {
$this->_id = $user->id;
$this->_isAdmin = ($user->user_type == Yii::app()->const->ADMIN_USER_TYPE) ? true : false;
$this->setState('user_type', $user->user_type);
$this->setState('username', $user->username);
}
return !$this->errorCode;
}
模范班
public function login() {
if ($this->_identity === null) {
$this->_identity = new UserIdentity($this->username, $this->password);
$this->_identity->authenticate();
}
if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
$duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days
Yii::app()->user->login($this->_identity, $duration);
return true;
}
else
return false;
}
我的代码有什么问题,为什么记得我不工作
还有,浏览器“记住我”和该站点“记住我在yii中”之间的区别是什么。一旦我记住我,请检查并登录并注销该站点。我再次运行登录url,这意味着用户名和密码都已放置,我是对的?您的配置文件缺少标识类配置。类似于'user'=>['identityClass'=>'app\components\user','enableAutoLogin'=>true,请发布完整的模型和视图代码