hi there;
I want to log with yii using last opend session but always when I close my Navigator I lose last session so I should log again using password and username, I dont know how to retrieve and use last session, like Gmail when I open it in my navigator my session still open entel I close it.
this is my code
class UserIdentity extends CUserIdentity{
public function authenticate(){
$client=User::model()->findByAttributes(array('username'=>$this->username));
if(empty($client)) $this->errorCode=self::ERROR_PASSWORD_INVALID;
else if(!empty($client)){
if(strcmp(md5($this->password), $client->password)!=0)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else if(strcmp(md5($this->password), $client->password)==0){
$this->_id=$client->username;
$this->setState('role', 'USER');
$compte=Comptecabinet::model()->findByPk($client->idcompte);
$this->errorCode=self::ERROR_NONE;
$this->setState('XthisX',$client->idcompte);
$this->setState('TimeConnexion',date("Y-m-d H:i"));
}
}
}
in model
public function authenticate($attribute,$params)
{
if(!$this->hasErrors())
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
$this->addError('password','Incorrect username or password.');
}
}
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;
Yii::app()->user->login($this->_identity,$duration);
return true;
}
else
return false;
}