Hello Guys,
In User table, I have one field, name lastLogin time. I can insert login time, but that is current login time. I want to display user’s last login time. Do I need two fields, lastLogin and currentLogin. If yes then how to update currentLogin field to lastLogin and insert new login time to currentLogin field when user login. I think I confuse U. Actually I want to display user’s last login time.
Here is my component/UserIdentity.php file
public function authenticate()
{
$user=User::model()->with('role')->find('LOWER(loginName)=?',array(strtolower($this->username)));
if($user===null)
{
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else if(md5($this->password)!==$user->password)
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else if($user->active == 0)
$this->errorCode=self::ERROR_STATUS_NOTACTIVE;
else
{
$this->_id=$user->id;
$this->username=$user->loginName;
$this->_role=$user->role->name; // save role for use in app
$this->errorCode=self::ERROR_NONE;
User::model()->updateByPk($user->id,array('lastLogin'=> date("Y-m-d H:i:s"), 'ip'=> $_SERVER['REMOTE_ADDR'] ));
$_SERVER['REMOTE_ADDR'] ));
$user_log= new UserLog();
$user_log->id=$user->id;
$user_log->time=date("Y-m-d H:i:s");
$user_log->ip=$_SERVER['REMOTE_ADDR'];
$user_log->save();
}
return !$this->errorCode;
}