Yii Framework Forum: Determine Last User Logged - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Determine Last User Logged Rate Topic: -----

#1 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 29 April 2010 - 12:39 PM

Hey,
How can I track, when user was logged in for the last time using Yii? When I used simply PHP, I redefined session storage to DB and was tracking session end, and put this time to the "lastLogged" field in the user table. How can I achieve this with Yii?
0

#2 User is offline   Vince. 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 432
  • Joined: 29-December 08
  • Location:Los Angeles,CA

Posted 29 April 2010 - 01:36 PM

Probably the same way, Make a column in the users table that will store the last login time and update it each time a member logs in.
Vince Gabriel, Lead Developer.
Posted ImagePosted ImagePosted Image
0

#3 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 29 April 2010 - 02:03 PM

View PostVince., on 29 April 2010 - 01:36 PM, said:

Probably the same way, Make a column in the users table that will store the last login time and update it each time a member logs in.


Is there any other solution? If not, then how to transfer newLogin dateTime to oldLogin time

here is my code
UserIdentity.php

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 if($user->locked == 0)
$this->errorCode=self::ERROR_STATUS_LOCKED;
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('newLogin'=> date("Y-m-d H:i:s"), 'ip'=> $_SERVER['REMOTE_ADDR'] ));
User::model()->updateByPk($user->id,array('oldLogin'=> date("Y-m-d H:i:s")));

$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;
}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users