欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

yii框架,设置自动登录以后,如何捕捉登录动作

程序员文章站 2024-02-07 12:20:10
...
yii框架,设置自动登录以后,怎么捕捉登录动作?
用的yii,实现了自动登录。现在的问题是,需要在用户登录的时候,记录下登录时间,请问应该在哪里做呢?
我现在是在component的 useridentity类下的authenticate方法里,记录用户登录时间的,但是貌似会漏掉。用户选自动登录的时候,有的时候貌似记录不到。

大大们,应该怎么弄啊?
------解决方案--------------------
大概是yiilite.php文件中的以下几行代码实现的自动登陆。我想你能看出原因来

public function init()
{
parent::init();
Yii::app()->getSession()->open();
if($this->getIsGuest() && $this->allowAutoLogin)
$this->restoreFromCookie();
else if($this->autoRenewCookie && $this->allowAutoLogin)
$this->renewCookie();
if($this->autoUpdateFlash)
$this->updateFlash();
$this->updateAuthStatus();
}
public function login($identity,$duration=0)
{
$id=$identity->getId();
$states=$identity->getPersistentStates();
if($this->beforeLogin($id,$states,false))
{
$this->changeIdentity($id,$identity->getName(),$states);
if($duration>0)
{
if($this->allowAutoLogin)
$this->saveToCookie($duration);
else
throw new CException(Yii::t('yii','{class}.allowAutoLogin must be set true in order to use cookie-based authentication.',
array('{class}'=>get_class($this))));
}
$this->afterLogin(false);
}
}


yii框架,设置自动登录以后,如何捕捉登录动作

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频