1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 25/12/2015
* Time: 2:13 CH
*/
class AdminSetting extends CI_Controller
{
public function __construct(){
parent::__construct();
//
date_default_timezone_set("Asia/Ho_Chi_Minh");
//
$this->load->model('admin_model');
$this->load->model('actionlog_model');
//
}
//==================================================================================================================
public function changePassword($id){
$this->_data['adminById'] = $this->admin_model->getById($id);
$userAdmin = $this->_data['adminById'];
// Kiểm tra quyền sửa: nếu là dcv_super_admin thì chỉ người đó mới có quyền sửa
if($this->session->userdata('id') != $id){
// Ghi log
$this->actionlog_model->add('RESET_PASSWORD', 'Cố ý cập nhật mật khẩu người khác có ID='.$id, 'AdminModel', 'admin', $id);
//
$this->session->set_flashdata('error', 'Bạn không có quyền cập nhật mật khẩu của user khác.');
redirect(base_url().'usersetting/changePassword/'.$this->session->userdata('id'));
}
// Kiểm tra trùng giá trị nếu thay đổi ở form
if($this->input->post('password') != ''){
$pwd_validate = '|required|min_length[8]';
$re_pwd_validate = '|required||min_length[8]|matches[password]';
} else{
$pwd_validate = '';
$re_pwd_validate = '';
}
// Thiết lập validate
$this->form_validation->set_rules('old_password', 'Mật khẩu cũ',
'required|trim|max_length[32]|xss_clean|callback_check_admin_old_password'
);
$this->form_validation->set_rules('password', 'Mật khẩu',
'required|trim|max_length[32]|xss_clean'.$pwd_validate
);
$this->form_validation->set_rules('password2', 'Nhập lại mật khẩu',
'required|trim|max_length[32]|xss_clean'.$re_pwd_validate
);
// Thiết lập message
$this->form_validation->set_message('required', '<li>Bắt buộc nhập hoặc chọn.</li>');
$this->form_validation->set_message('is_unique', '<li>Đã tồn tại.</li>');
$this->form_validation->set_message('max_length', '<li>Tối đa 32 ký tự.</li>');
$this->form_validation->set_message('min_length', '<li>Tối thiểu 8 ký tự.</li>');
$this->form_validation->set_message('matches', '<li>Nhập lại mật khẩu không đúng.</li>');
// Xử lý form đăng nhập
if($this->form_validation->run($this) == FALSE){
$this->_data['old_password'] = $this->input->post('old_password');
$this->_data['password'] = $this->input->post('password');
$this->_data['password2'] = $this->input->post('password2');
//
$this->_data['functionName'] = 'Người dùng hệ thống';
$this->_data['action'] = 'changePassword';
$this->_data['titlePage'] = 'Người dùng hệ thống';
$this->_data['loadPage'] = 'backend/admin_setting/change_pwd_admin_view';
$this->load->view('backend/admin_template_view', $this->_data);
}else{
// Insert Nhóm vào DB
$dataUpdate = array();
if(trim($this->input->post('password')) != ''){
$dataUpdate['password'] = MyHelper::genKeyCode(trim($this->input->post('password')));
$this->admin_model->update($id, $dataUpdate);
$this->session->set_flashdata('success', 'Cập nhật thành công mật khẩu.');
// Ghi log
$this->actionlog_model->add('RESET_PASSWORD', 'Cập nhật mật khẩu người dùng', 'AdminModel', 'admin', $id);
//
}
redirect(base_url('adminSetting/changePassword/'.$userAdmin[0]['id']));
}
}
public function check_admin_old_password($pwd){
$userAdmin = $this->_data['adminById'];
if(MyHelper::genKeyCode($pwd) != $userAdmin[0]['password']){
$this->form_validation->set_message('check_admin_old_password', '<li>Mật khẩu cũ không đúng.</li>');
return FALSE;
}else{
return TRUE;
}
}
public function userInfo($id){
// Kiểm tra quyền xem: chỉ xem thông tin của mình
if($this->session->userdata('id') != $id){
// Ghi log
$this->actionlog_model->add('SHOW_USER_INFO', 'Cố ý xem thông tin cá nhân người khác có ID='.$id, 'AdminModel', 'admin', $id);
//
$this->session->set_flashdata('error', 'Bạn không có quyền xem thông tin cá nhân người khác.');
redirect(base_url('adminSetting/userInfo/'.$this->session->userdata('id')));
}
//
$this->_data['adminById'] = $this->admin_model->getById($id);
//
$this->_data['functionName'] = 'Người dùng hệ thống';
$this->_data['action'] = 'userInfo';
$this->_data['titlePage'] = 'Thông tin tài khoản';
$this->_data['loadPage'] = 'backend/admin_setting/admin_info_view';
$this->load->view('backend/admin_template_view', $this->_data);
}
}