用户管理、认证与访问控制实现指南
1. 用户最后登录时间更新
在用户创建表单中,我们移除了最后登录时间作为输入字段,但仍需添加逻辑来正确更新该字段。由于我们在 tbl_user 数据库表中跟踪最后登录时间,因此在用户成功登录后,需要相应地更新该字段。具体操作是在表单模型类的 LoginForm::login() 方法中更新该值,添加以下高亮代码:
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
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->_iden
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



