你好,我是Yii的新手,下面是我的UserIdentiy函数,请告诉我如何添加记住我的功能
public function authenticate()
{
$users = array();
if ($this->usertype == "registration")
{
$users = Login::model()->findByAttributes(array('email' => $this->username));
$users = $users->attributes;
}
if (empty($users)) $this->errorCode = self::ERROR_USERNAME_INVALID;
elseif (!empty($users['password']) && $users['password'] !== md5($this->password))
$this->errorCode = self::ERROR_PASSWORD_INVALID;
elseif (!empty($users['status']) && $users['status'] !== 1)
$this->errorCode = self::STATUS_NOT_ACTIVE;
else
{
$this->_id = $users->id;
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
2条答案
按热度按时间kd3sttzy1#
在
protected\config\main.php
配置数组中存在该数组,转到component
索引。在该user
数组中,具有关联索引值'allowAutoLogin'
,必须具有布尔值true
因此,它应该如下所示
你必须使用下面的属性沿着下面给出的登录方法,你可以很容易地实现记住我。
在Login模型类中,login方法应该如下所示
这是记忆函数的核心代码
z9ju0rcb2#
给你
/**LoginForm类。 LoginForm是用于保存 * 用户登录窗体数据的数据结构。它由“SiteController”的“登录”操作使用。*/ class LoginFormUser扩展了CFormModel {
}