Home >Backend Development >PHP Tutorial > yii框架,设置自动登录以后,如何捕捉登录动作

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

WBOY
WBOYOriginal
2016-06-13 12:57:40923browse

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

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

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


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn