Skip to content

Commit 16f3083

Browse files
committed
las login tracking of user
1 parent d13e2f4 commit 16f3083

File tree

3 files changed

+57
-29
lines changed

3 files changed

+57
-29
lines changed

application/controllers/login.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,14 @@ public function loginMe()
7575
'name'=>$res->name,
7676
'isLoggedIn' => TRUE
7777
);
78-
78+
7979
$this->session->set_userdata($sessionArray);
80+
81+
unset($sessionArray['isLoggedIn']);
82+
83+
$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());
84+
85+
$this->login_model->lastLogin($loginInfo);
8086

8187
redirect('/dashboard');
8288
}

application/models/login_model.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ function createPasswordUser($email, $password)
105105
$this->db->update('tbl_users', array('password'=>getHashedPassword($password)));
106106
$this->db->delete('tbl_reset_password', array('email'=>$email));
107107
}
108+
109+
/**
110+
* This function used to save login information of user
111+
* @param array $loginInfo : This is users login information
112+
*/
113+
function lastLogin($loginInfo)
114+
{
115+
$this->db->trans_start();
116+
$this->db->insert('tbl_last_login', $loginInfo);
117+
$this->db->trans_complete();
118+
}
108119
}
109120

110121
?>

cias.sql

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
-- http://www.phpmyadmin.net
44
--
55
-- Host: 127.0.0.1
6-
-- Generation Time: Mar 03, 2017 at 12:09 PM
7-
-- Server version: 10.1.13-MariaDB
8-
-- PHP Version: 5.5.35
6+
-- Generation Time: Jan 02, 2018 at 10:44 AM
7+
-- Server version: 10.1.16-MariaDB
8+
-- PHP Version: 5.6.24
99

1010
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
1111
SET time_zone = "+00:00";
@@ -23,29 +23,33 @@ SET time_zone = "+00:00";
2323
-- --------------------------------------------------------
2424

2525
--
26-
-- Table structure for table `tbl_items`
26+
-- Table structure for table `ci_sessions`
2727
--
2828

29-
CREATE TABLE `tbl_items` (
30-
`itemId` int(11) NOT NULL,
31-
`itemHeader` varchar(512) NOT NULL COMMENT 'Heading',
32-
`itemSub` varchar(1021) NOT NULL COMMENT 'sub heading',
33-
`itemDesc` text COMMENT 'content or description',
34-
`itemImage` varchar(80) DEFAULT NULL,
35-
`isDeleted` tinyint(4) NOT NULL DEFAULT '0',
36-
`createdBy` int(11) NOT NULL,
37-
`createdDtm` datetime NOT NULL,
38-
`updatedDtm` datetime DEFAULT NULL,
39-
`updatedBy` int(11) DEFAULT NULL
40-
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
29+
CREATE TABLE `ci_sessions` (
30+
`session_id` varchar(40) NOT NULL DEFAULT '0',
31+
`ip_address` varchar(45) NOT NULL DEFAULT '0',
32+
`user_agent` varchar(120) NOT NULL,
33+
`last_activity` int(10) UNSIGNED NOT NULL DEFAULT '0',
34+
`user_data` text NOT NULL
35+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
36+
37+
-- --------------------------------------------------------
4138

4239
--
43-
-- Dumping data for table `tbl_items`
40+
-- Table structure for table `tbl_last_login`
4441
--
4542

46-
INSERT INTO `tbl_items` (`itemId`, `itemHeader`, `itemSub`, `itemDesc`, `itemImage`, `isDeleted`, `createdBy`, `createdDtm`, `updatedDtm`, `updatedBy`) VALUES
47-
(1, 'jquery.validation.js', 'Contribution towards jquery.validation.js', 'jquery.validation.js is the client side javascript validation library authored by Jörn Zaefferer hosted on github for us and we are trying to contribute to it. Working on localization now', 'validation.png', 0, 1, '2015-09-02 00:00:00', NULL, NULL),
48-
(2, 'CodeIgniter User Management', 'Demo for user management system', 'This the demo of User Management System (Admin Panel) using CodeIgniter PHP MVC Framework and AdminLTE bootstrap theme. You can download the code from the repository or forked it to contribute. Usage and installation instructions are provided in ReadMe.MD', 'cias.png', 0, 1, '2015-09-02 00:00:00', NULL, NULL);
43+
CREATE TABLE `tbl_last_login` (
44+
`id` bigint(20) NOT NULL,
45+
`userId` bigint(20) NOT NULL,
46+
`sessionData` varchar(2048) NOT NULL,
47+
`machineIp` varchar(1024) NOT NULL,
48+
`userAgent` varchar(128) NOT NULL,
49+
`agentString` varchar(1024) NOT NULL,
50+
`platform` varchar(128) NOT NULL,
51+
`createdDtm` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
52+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4953

5054
-- --------------------------------------------------------
5155

@@ -111,7 +115,7 @@ CREATE TABLE `tbl_users` (
111115
--
112116

113117
INSERT INTO `tbl_users` (`userId`, `email`, `password`, `name`, `mobile`, `roleId`, `isDeleted`, `createdBy`, `createdDtm`, `updatedBy`, `updatedDtm`) VALUES
114-
(1, '[email protected]', '$2y$10$WQQRBQDkxV/98bqK.24Dp.uMVS6KcztVqdwwTrOBLIWLSeSqE2gii', 'System Administrator', '9890098900', 1, 0, 0, '2015-07-01 18:56:49', 1, '2017-03-03 12:08:39'),
118+
(1, '[email protected]', '$2y$10$ZY3F9lR2.x7yQFP9/2iEKOnYLis9CnbD6CqWaM1dJYtebMq6JZLka', 'System Administrator', '9890098900', 1, 0, 0, '2015-07-01 18:56:49', 1, '2017-03-03 12:08:39'),
115119
(2, '[email protected]', '$2y$10$quODe6vkNma30rcxbAHbYuKYAZQqUaflBgc4YpV9/90ywd.5Koklm', 'Manager', '9890098900', 2, 0, 1, '2016-12-09 17:49:56', 1, '2017-02-10 17:23:53'),
116120
(3, '[email protected]', '$2y$10$M3ttjnzOV2lZSigBtP0NxuCtKRte70nc8TY5vIczYAQvfG/8syRze', 'Employee', '9890098900', 3, 0, 1, '2016-12-09 17:50:22', NULL, NULL);
117121

@@ -120,10 +124,17 @@ INSERT INTO `tbl_users` (`userId`, `email`, `password`, `name`, `mobile`, `roleI
120124
--
121125

122126
--
123-
-- Indexes for table `tbl_items`
127+
-- Indexes for table `ci_sessions`
128+
--
129+
ALTER TABLE `ci_sessions`
130+
ADD PRIMARY KEY (`session_id`),
131+
ADD KEY `last_activity_idx` (`last_activity`);
132+
124133
--
125-
ALTER TABLE `tbl_items`
126-
ADD PRIMARY KEY (`itemId`);
134+
-- Indexes for table `tbl_last_login`
135+
--
136+
ALTER TABLE `tbl_last_login`
137+
ADD PRIMARY KEY (`id`);
127138

128139
--
129140
-- Indexes for table `tbl_reset_password`
@@ -148,15 +159,15 @@ ALTER TABLE `tbl_users`
148159
--
149160

150161
--
151-
-- AUTO_INCREMENT for table `tbl_items`
162+
-- AUTO_INCREMENT for table `tbl_last_login`
152163
--
153-
ALTER TABLE `tbl_items`
154-
MODIFY `itemId` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
164+
ALTER TABLE `tbl_last_login`
165+
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
155166
--
156167
-- AUTO_INCREMENT for table `tbl_reset_password`
157168
--
158169
ALTER TABLE `tbl_reset_password`
159-
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=22;
170+
MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;
160171
--
161172
-- AUTO_INCREMENT for table `tbl_roles`
162173
--

0 commit comments

Comments
 (0)