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