Skip to content

Commit 1d62a28

Browse files
committed
last login updated in header
1 parent e027603 commit 1d62a28

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

application/controllers/login.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,19 @@ public function loginMe()
6969
{
7070
foreach ($result as $res)
7171
{
72+
$lastLogin = $this->login_model->lastLoginInfo($res->userId);
73+
7274
$sessionArray = array('userId'=>$res->userId,
7375
'role'=>$res->roleId,
7476
'roleText'=>$res->role,
7577
'name'=>$res->name,
78+
'lastLogin'=> $lastLogin->createdDtm,
7679
'isLoggedIn' => TRUE
7780
);
7881

7982
$this->session->set_userdata($sessionArray);
8083

81-
unset($sessionArray['isLoggedIn']);
84+
unset($sessionArray['isLoggedIn'], $sessionArray['lastLogin']);
8285

8386
$loginInfo = array("userId"=>$res->userId, "sessionData" => json_encode($sessionArray), "machineIp"=>$this->input->ip_address(), "userAgent"=>getBrowserAgent(), "agentString"=>$this->agent->agent_string(), "platform"=>$this->agent->platform());
8487

application/libraries/BaseController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class BaseController extends CI_Controller {
1313
protected $name = '';
1414
protected $roleText = '';
1515
protected $global = array ();
16+
protected $lastLogin = '';
1617

1718
/**
1819
* Takes mixed data and optionally a status code, then creates the response
@@ -40,10 +41,12 @@ function isLoggedIn() {
4041
$this->vendorId = $this->session->userdata ( 'userId' );
4142
$this->name = $this->session->userdata ( 'name' );
4243
$this->roleText = $this->session->userdata ( 'roleText' );
44+
$this->lastLogin = $this->session->userdata ( 'lastLogin' );
4345

4446
$this->global ['name'] = $this->name;
4547
$this->global ['role'] = $this->role;
4648
$this->global ['role_text'] = $this->roleText;
49+
$this->global ['last_login'] = $this->lastLogin;
4750
}
4851
}
4952

application/models/login_model.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ function lastLogin($loginInfo)
116116
$this->db->insert('tbl_last_login', $loginInfo);
117117
$this->db->trans_complete();
118118
}
119+
120+
function lastLoginInfo($userId)
121+
{
122+
$this->db->select('BaseTbl.createdDtm');
123+
$this->db->where('BaseTbl.userId', $userId);
124+
$this->db->order_by('BaseTbl.id', 'DESC');
125+
$this->db->limit(1);
126+
$query = $this->db->get('tbl_last_login as BaseTbl');
127+
128+
return $query->row();
129+
}
119130
}
120131

121132
?>

application/views/includes/header.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@
5353
</a>
5454
<div class="navbar-custom-menu">
5555
<ul class="nav navbar-nav">
56-
<li>
57-
<a href="<?= base_url() ?>login-history"><i class="fa fa-history"></i></a>
56+
<li class="dropdown tasks-menu">
57+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">
58+
<i class="fa fa-history"></i>
59+
</a>
60+
<ul class="dropdown-menu">
61+
<li class="header"> Last Login : <i class="fa fa-clock-o"></i> <?= $last_login ?></li>
62+
</ul>
5863
</li>
5964
<!-- User Account: style can be found in dropdown.less -->
6065
<li class="dropdown user user-menu">

0 commit comments

Comments
 (0)