I didn’t find what I was looking for so here is what I did in case there is someone else looking for the samething:
Modify the users table to be like so:
CREATE TABLE `tcs_users` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`group_id` mediumint(8) unsigned NOT NULL,
`ip_address` char(16) NOT NULL,
`username` varchar(15) NOT NULL,
`password` varchar(40) NOT NULL,
`salt` varchar(40) DEFAULT NULL,
`email` varchar(100) NOT NULL,
`activation_code` varchar(40) DEFAULT NULL,
`forgotten_password_code` varchar(40) DEFAULT NULL,
`remember_code` varchar(40) DEFAULT NULL,
`created_on` int(11) unsigned NOT NULL,
`last_login` int(11) unsigned DEFAULT NULL,
`last_login_ip` varchar(20) DEFAULT NULL,
`active` tinyint(1) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Notice the addition of last_login_ip
I then modified the ion_auth_model.php file located in the models directory (there are two modifications made):
First change was with the login function lines 560-615:
/**
* login
*
* @return bool
* @author Mathew
**/
public function login($identity, $password, $remember=FALSE)
{
if (empty($identity) || empty($password) || !$this->identity_check($identity))
{
return FALSE;
}
$query = $this->db->select($this->identity_column.', id, password, group_id, last_login, ip_address')
->where($this->identity_column, $identity)
->where('active', 1)
->where($this->ion_auth->_extra_where)
->limit(1)
->get($this->tables['users']);
$result = $query->row();
if ($query->num_rows() == 1)
{
$password = $this->hash_password_db($identity, $password);
if ($result->password === $password)
{
$group_row = $this->db->select('name')->where('id', $result->group_id)->get($this->tables['groups'])->row();
$session_data = array(
$this->identity_column => $result->{$this->identity_column},
'id' => $result->id, //kept for backwards compatibility
'user_id' => $result->id, //everyone likes to overwrite id so we'll use user_id
'group_id' => $result->group_id,
'group' => $group_row->name,
'userlastlogin' => $result->last_login,
'userlastloginip' => $this->session->userdata('ip_address')
);
$this->session->set_userdata($session_data);
$this->update_last_login($result->id, $this->session->userdata('ip_address'));
if ($remember && $this->config->item('remember_users', 'ion_auth'))
{
$this->remember_user($result->id);
}
return TRUE;
}
}
return FALSE;
}
Next I changed the update_last_login function lines 969-987:
/**
* update_last_login
*
* @return bool
* @author Ben Edmunds
**/
public function update_last_login($id,$lastloginip)
{
$this->load->helper('date');
if (isset($this->ion_auth->_extra_where) && !empty($this->ion_auth->_extra_where))
{
$this->db->where($this->ion_auth->_extra_where);
}
$this->db->update($this->tables['users'], array('last_login' => now(), 'last_login_ip' => $lastloginip), array('id' => $id));
return $this->db->affected_rows() == 1;
}
Now the users last login will be available via session data like so:
echo $this->session->userdata('userlastlogin')
echo $this->session->userdata('userlastloginip')
Hope this helps. Might already be in there somewhere but I could not find it. This will allow you to print out the last login for this user not the current login.
Regards,
Ray