日期:2014-05-17  浏览次数:20495 次

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);
}
}