Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vmusicchart-cms
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phạm Văn Đoan
vmusicchart-cms
Commits
f9592139
Commit
f9592139
authored
Apr 15, 2020
by
Phạm Văn Đoan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cập nhật: lấy IP client để lưu vào log vào/ra
parent
fc10bef1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
19 deletions
+80
-19
Account.php
application/controllers/backend/Account.php
+4
-3
Userlog_model.php
application/models/Userlog_model.php
+64
-14
login_view.php
application/views/backend/login_view.php
+12
-2
No files found.
application/controllers/backend/Account.php
View file @
f9592139
...
@@ -42,10 +42,11 @@ class Account extends CI_Controller
...
@@ -42,10 +42,11 @@ class Account extends CI_Controller
if
(
$this
->
form_validation
->
run
(
$this
)
==
FALSE
)
{
if
(
$this
->
form_validation
->
run
(
$this
)
==
FALSE
)
{
$this
->
load
->
view
(
'backend/login_view'
);
$this
->
load
->
view
(
'backend/login_view'
);
}
else
{
}
else
{
$client_ip
=
trim
(
$this
->
input
->
post
(
'client_ip'
));
$username
=
trim
(
$this
->
input
->
post
(
'txtUsername'
));
$username
=
trim
(
$this
->
input
->
post
(
'txtUsername'
));
$password
=
MyHelper
::
genKeyCode
(
trim
(
$this
->
input
->
post
(
'txtPassword'
)));
$password
=
MyHelper
::
genKeyCode
(
trim
(
$this
->
input
->
post
(
'txtPassword'
)));
$checkUserAdmin
=
$this
->
admin_model
->
getUserAdminLogin
(
$username
,
$password
);
$checkUserAdmin
=
$this
->
admin_model
->
getUserAdminLogin
(
$username
,
$password
);
//
MyHelper::echoPreDie($checkUserAdmin);
//
if
(
$checkUserAdmin
)
{
if
(
$checkUserAdmin
)
{
// Thiết lập session
// Thiết lập session
$sessionData
=
array
(
$sessionData
=
array
(
...
@@ -59,7 +60,7 @@ class Account extends CI_Controller
...
@@ -59,7 +60,7 @@ class Account extends CI_Controller
);
);
// Ghi log
// Ghi log
$user_log_id
=
$this
->
userlog_model
->
add
(
'LOGIN/LOGOUT'
,
$this
->
input
->
post
(
'txtUsername'
),
'SUCCESS'
);
$user_log_id
=
$this
->
userlog_model
->
add
(
'LOGIN/LOGOUT'
,
$this
->
input
->
post
(
'txtUsername'
),
'SUCCESS'
,
$client_ip
);
$sessionData
[
'user_log_id'
]
=
$user_log_id
;
$sessionData
[
'user_log_id'
]
=
$user_log_id
;
$sessionData
[
'time_login'
]
=
date
(
'Y-m-d H:i:s'
);
$sessionData
[
'time_login'
]
=
date
(
'Y-m-d H:i:s'
);
$this
->
session
->
set_userdata
(
$sessionData
);
$this
->
session
->
set_userdata
(
$sessionData
);
...
@@ -68,7 +69,7 @@ class Account extends CI_Controller
...
@@ -68,7 +69,7 @@ class Account extends CI_Controller
redirect
(
base_url
(
'backend/home/index'
));
redirect
(
base_url
(
'backend/home/index'
));
}
else
{
}
else
{
// Ghi log
// Ghi log
$this
->
userlog_model
->
add
(
'LOGIN'
,
$this
->
input
->
post
(
'txtUsername'
),
'FAILED'
);
$this
->
userlog_model
->
add
(
'LOGIN'
,
$this
->
input
->
post
(
'txtUsername'
),
'FAILED'
,
$client_ip
);
// Chuyển trang
// Chuyển trang
$this
->
session
->
set_flashdata
(
'loginErrorMsg'
,
'Đăng nhập không thành công!'
);
$this
->
session
->
set_flashdata
(
'loginErrorMsg'
,
'Đăng nhập không thành công!'
);
...
...
application/models/Userlog_model.php
View file @
f9592139
...
@@ -8,12 +8,22 @@ class Userlog_model extends CI_Model {
...
@@ -8,12 +8,22 @@ class Userlog_model extends CI_Model {
date_default_timezone_set
(
"Asia/Ho_Chi_Minh"
);
date_default_timezone_set
(
"Asia/Ho_Chi_Minh"
);
}
}
public
function
add
(
$action
,
$account_input
,
$result
,
$type
=
'BE'
){
/**
* Hàm lưu log vào/ra hệ thống
*
* @param $action
* @param $account_input
* @param $result
* @param null $ip
* @param string $type
* @return mixed
*/
public
function
add
(
$action
,
$account_input
,
$result
,
$ip
=
null
,
$type
=
'BE'
){
$dataInsert
=
array
(
$dataInsert
=
array
(
'action'
=>
$action
,
'action'
=>
$action
,
'time_login'
=>
date
(
'Y-m-d H:i:s'
),
'time_login'
=>
date
(
'Y-m-d H:i:s'
),
'account_input'
=>
$account_input
,
'account_input'
=>
$account_input
,
'ip_address'
=>
$
this
->
input
->
ip_address
()
,
'ip_address'
=>
$
ip
,
'user_agent'
=>
$this
->
input
->
user_agent
(),
'user_agent'
=>
$this
->
input
->
user_agent
(),
'type'
=>
$type
,
'type'
=>
$type
,
'result'
=>
$result
'result'
=>
$result
...
@@ -23,6 +33,12 @@ class Userlog_model extends CI_Model {
...
@@ -23,6 +33,12 @@ class Userlog_model extends CI_Model {
return
$insert_id
;
return
$insert_id
;
}
}
/**
* Hàm update thời gian sử dụng hệ thống
*
* @param $id
* @param $time_login
*/
public
function
update
(
$id
,
$time_login
){
public
function
update
(
$id
,
$time_login
){
$time_logout
=
date
(
'Y-m-d H:i:s'
);
$time_logout
=
date
(
'Y-m-d H:i:s'
);
$duration
=
(
int
)(
strtotime
(
$time_logout
)
-
strtotime
(
$time_login
));
$duration
=
(
int
)(
strtotime
(
$time_logout
)
-
strtotime
(
$time_login
));
...
@@ -34,11 +50,22 @@ class Userlog_model extends CI_Model {
...
@@ -34,11 +50,22 @@ class Userlog_model extends CI_Model {
$this
->
db
->
update
(
$this
->
_table
,
$dataUpdate
);
$this
->
db
->
update
(
$this
->
_table
,
$dataUpdate
);
}
}
/**
* Hàm xóa thông tin log vào/ra
*
* @param $id
*/
public
function
delete
(
$id
){
public
function
delete
(
$id
){
$this
->
db
->
where
(
'id'
,
$id
);
$this
->
db
->
where
(
'id'
,
$id
);
$this
->
db
->
delete
(
$this
->
_table
);
$this
->
db
->
delete
(
$this
->
_table
);
}
}
/**
* Hàm lấy thông tin chi tiết log vào/ra
*
* @param $id
* @return mixed
*/
public
function
getById
(
$id
){
public
function
getById
(
$id
){
$this
->
db
->
select
(
$this
->
_table
.
'.*'
);
$this
->
db
->
select
(
$this
->
_table
.
'.*'
);
$this
->
db
->
from
(
$this
->
_table
);
$this
->
db
->
from
(
$this
->
_table
);
...
@@ -47,15 +74,25 @@ class Userlog_model extends CI_Model {
...
@@ -47,15 +74,25 @@ class Userlog_model extends CI_Model {
return
$query
->
result_array
();
return
$query
->
result_array
();
}
}
public
function
countAll
(
$dtFrom
=
NULL
,
$dtTo
=
NULL
,
$filterByIP
=
NULL
,
$filterByAccount
=
NULL
,
$filterByResult
=
NULL
){
/**
* Hàm lấy tổng số bản ghi log vào/ra
*
* @param null $dtFrom
* @param null $dtTo
* @param null $filterByIP
* @param null $filterByAccount
* @param null $filterByResult
* @return int
*/
public
function
countAll
(
$dtFrom
=
null
,
$dtTo
=
null
,
$filterByIP
=
null
,
$filterByAccount
=
null
,
$filterByResult
=
null
){
$this
->
db
->
select
(
'COUNT(*) AS totalResults'
);
$this
->
db
->
select
(
'COUNT(*) AS totalResults'
);
$this
->
db
->
from
(
$this
->
_table
);
$this
->
db
->
from
(
$this
->
_table
);
if
(
$dtFrom
!=
NULL
){
$this
->
db
->
where
(
'DATE(time_login) >='
,
$dtFrom
);}
if
(
$dtFrom
!=
null
){
$this
->
db
->
where
(
'DATE(time_login) >='
,
$dtFrom
);}
if
(
$dtTo
!=
NULL
){
$this
->
db
->
where
(
'DATE(time_login) <='
,
$dtTo
);}
if
(
$dtTo
!=
null
){
$this
->
db
->
where
(
'DATE(time_login) <='
,
$dtTo
);}
if
(
$filterByIP
!=
NULL
){
$this
->
db
->
like
(
'ip_address'
,
$filterByIP
);}
if
(
$filterByIP
!=
null
){
$this
->
db
->
like
(
'ip_address'
,
$filterByIP
);}
if
(
$filterByAccount
!=
NULL
){
$this
->
db
->
like
(
'account_input'
,
$filterByAccount
);}
if
(
$filterByAccount
!=
null
){
$this
->
db
->
like
(
'account_input'
,
$filterByAccount
);}
if
(
$filterByResult
!=
NULL
){
$this
->
db
->
where
(
'UPPER(result)'
,
$filterByResult
);}
if
(
$filterByResult
!=
null
){
$this
->
db
->
where
(
'UPPER(result)'
,
$filterByResult
);}
$query
=
$this
->
db
->
get
();
$query
=
$this
->
db
->
get
();
$result
=
$query
->
result_array
();
$result
=
$query
->
result_array
();
...
@@ -66,15 +103,28 @@ class Userlog_model extends CI_Model {
...
@@ -66,15 +103,28 @@ class Userlog_model extends CI_Model {
}
}
}
}
public
function
getPagination
(
$record
,
$start
,
$dtFrom
=
NULL
,
$dtTo
=
NULL
,
$filterByIP
=
NULL
,
$filterByAccount
=
NULL
,
$filterByResult
=
NULL
){
/**
* Hàm lấy dữ liệu phân trang log vào/ra
*
* @param $record
* @param $start
* @param null $dtFrom
* @param null $dtTo
* @param null $filterByIP
* @param null $filterByAccount
* @param null $filterByResult
*
* @return mixed
*/
public
function
getPagination
(
$record
,
$start
,
$dtFrom
=
null
,
$dtTo
=
null
,
$filterByIP
=
null
,
$filterByAccount
=
null
,
$filterByResult
=
null
){
$this
->
db
->
select
(
$this
->
_table
.
'.*'
);
$this
->
db
->
select
(
$this
->
_table
.
'.*'
);
$this
->
db
->
from
(
$this
->
_table
);
$this
->
db
->
from
(
$this
->
_table
);
if
(
$dtFrom
!=
NULL
){
$this
->
db
->
where
(
'DATE(time_login) >='
,
$dtFrom
);}
if
(
$dtFrom
!=
null
){
$this
->
db
->
where
(
'DATE(time_login) >='
,
$dtFrom
);}
if
(
$dtTo
!=
NULL
){
$this
->
db
->
where
(
'DATE(time_login) <='
,
$dtTo
);}
if
(
$dtTo
!=
null
){
$this
->
db
->
where
(
'DATE(time_login) <='
,
$dtTo
);}
if
(
$filterByIP
!=
NULL
){
$this
->
db
->
like
(
'ip_address'
,
$filterByIP
);}
if
(
$filterByIP
!=
null
){
$this
->
db
->
like
(
'ip_address'
,
$filterByIP
);}
if
(
$filterByAccount
!=
NULL
){
$this
->
db
->
like
(
'account_input'
,
$filterByAccount
);}
if
(
$filterByAccount
!=
null
){
$this
->
db
->
like
(
'account_input'
,
$filterByAccount
);}
if
(
$filterByResult
!=
NULL
){
$this
->
db
->
where
(
'UPPER(result)'
,
$filterByResult
);}
if
(
$filterByResult
!=
null
){
$this
->
db
->
where
(
'UPPER(result)'
,
$filterByResult
);}
$this
->
db
->
order_by
(
$this
->
_table
.
'.id'
,
'desc'
);
$this
->
db
->
order_by
(
$this
->
_table
.
'.id'
,
'desc'
);
$this
->
db
->
limit
(
$record
,
$start
);
$this
->
db
->
limit
(
$record
,
$start
);
...
...
application/views/backend/login_view.php
View file @
f9592139
...
@@ -31,7 +31,7 @@ $buttonLogin = array(
...
@@ -31,7 +31,7 @@ $buttonLogin = array(
<meta
http-equiv=
"refresh"
content=
"1800"
/>
<meta
http-equiv=
"refresh"
content=
"1800"
/>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
<title>
Đăng nhập CMS
</title>
<title>
Đăng nhập CMS
</title>
<link
rel=
"shortcut icon"
href=
"
<?php
echo
base_url
(
)
?>
images/favicon.png
"
sizes=
"24x24"
type=
"image/png"
/>
<link
rel=
"shortcut icon"
href=
"
<?php
echo
base_url
(
'images/favicon.png'
)
?>
"
sizes=
"24x24"
type=
"image/png"
/>
<meta
name=
"description"
content=
"User login page"
/>
<meta
name=
"description"
content=
"User login page"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0"
/>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0, maximum-scale=1.0"
/>
<!-- bootstrap & fontawesome -->
<!-- bootstrap & fontawesome -->
...
@@ -39,6 +39,7 @@ $buttonLogin = array(
...
@@ -39,6 +39,7 @@ $buttonLogin = array(
<link
rel=
"stylesheet"
href=
"
<?php
echo
base_url
(
'public/assets/font-awesome/4.2.0/css/font-awesome.min.css'
)
?>
"
/>
<link
rel=
"stylesheet"
href=
"
<?php
echo
base_url
(
'public/assets/font-awesome/4.2.0/css/font-awesome.min.css'
)
?>
"
/>
<!-- ace styles -->
<!-- ace styles -->
<link
rel=
"stylesheet"
href=
"
<?php
echo
base_url
(
'public/assets/css/ace.min.css'
)
?>
"
/>
<link
rel=
"stylesheet"
href=
"
<?php
echo
base_url
(
'public/assets/css/ace.min.css'
)
?>
"
/>
<script
src=
"
<?php
echo
base_url
(
'public/assets/js/jquery.2.1.1.min.js'
)
?>
"
></script>
</head>
</head>
...
@@ -74,7 +75,7 @@ $buttonLogin = array(
...
@@ -74,7 +75,7 @@ $buttonLogin = array(
?>
?>
<fieldset>
<fieldset>
<div>
<div>
<input
type=
"hidden"
name=
"client_ip"
value=
""
>
<input
type=
"hidden"
name=
"client_ip"
id=
"client_ip"
value=
""
>
</div>
</div>
<label
class=
"block clearfix"
>
<label
class=
"block clearfix"
>
<span
class=
"block input-icon input-icon-right"
>
<span
class=
"block input-icon input-icon-right"
>
...
@@ -113,5 +114,14 @@ $buttonLogin = array(
...
@@ -113,5 +114,14 @@ $buttonLogin = array(
<!-- /.main-content -->
<!-- /.main-content -->
</div>
</div>
<!-- /.main-container -->
<!-- /.main-container -->
<script>
$
.
getJSON
(
'https://jsonip.com/?callback=?'
,
function
(
data
)
{
var
ip
=
'unknow'
;
if
(
data
!==
null
)
{
ip
=
data
.
ip
;
}
$
(
'#client_ip'
).
val
(
ip
);
});
</script>
</body>
</body>
</html>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment