admin_login_729_2
This commit is contained in:
+12
-23
@@ -29,38 +29,33 @@ class Login extends CI_Controller
|
||||
$check_view = false;
|
||||
$ip = get_client_ip();
|
||||
$ip_arr = array();
|
||||
|
||||
if ($this->input->post('need_code') == 'get') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$log = 0;//加日志
|
||||
if ($this->input->post('need_code') == 'login') {
|
||||
$code = $this->input->post('code');
|
||||
$mobile = $this->input->post('mobile');
|
||||
$cookie = $this->input->cookie(LOGIN_CODE_COOKIE);
|
||||
$code_cookie = $this->encryption->decrypt($cookie);
|
||||
|
||||
if (!$code_cookie) {
|
||||
return $this->show_json(0, '验证码已过期');
|
||||
}
|
||||
if ($code_cookie != $code) {
|
||||
return $this->show_json(0, '验证码错误');
|
||||
}
|
||||
|
||||
$this->load->model('sys/sys_admin_model');
|
||||
$admin_user = $this->sys_admin_model->get(array("mobile = '{$mobile}'" => null, 'status' => 1));
|
||||
$log = 1;
|
||||
} else {
|
||||
if (!$username) {
|
||||
return $this->show_json(0, '请输入用户名/手机号');
|
||||
}
|
||||
|
||||
if (!$password) {
|
||||
return $this->show_json(0, '请输入密码');
|
||||
}
|
||||
|
||||
$this->load->model('sys/sys_admin_model');
|
||||
$admin_user = $this->sys_admin_model->get(array("username like '{$username}' OR mobile like '{$username}'" => null, 'status' => 1));
|
||||
|
||||
if (!$admin_user['id']) {
|
||||
return $this->show_json(0, '用户不存在');
|
||||
} elseif (!$admin_user['status']) {
|
||||
@@ -68,38 +63,34 @@ class Login extends CI_Controller
|
||||
} elseif (!password_verify($password, $admin_user['password'])) {
|
||||
return $this->show_json(0, '密码错误');
|
||||
} else {
|
||||
if(false !== strpos($_SERVER['HTTP_HOST'], "admin.dev.liche.cn") || false !== strpos($_SERVER['HTTP_HOST'], "admin.lc.haodian.cn")){
|
||||
//开发测试不校验IP
|
||||
}elseif (filter_var($ip, FILTER_VALIDATE_IP)) {
|
||||
if (false !== strpos($_SERVER['HTTP_HOST'], "admin.dev.liche.cn") || false !== strpos($_SERVER['HTTP_HOST'], "admin.lc.haodian.cn")) {
|
||||
//开发测试不校验IP
|
||||
} elseif (filter_var($ip, FILTER_VALIDATE_IP)) {
|
||||
$this->load->model('sys/sys_config_model');
|
||||
$config_ip = $this->sys_config_model->select(array("v LIKE '%\"status\":\"1\"%'" => NULL, "k" => "site"));
|
||||
foreach ($config_ip as $key => $value) {
|
||||
$ip_arr[] = json_decode($value['v'])->ip;
|
||||
}
|
||||
|
||||
$ip_arr = array_merge($ip_arr, array_column($this->sys_admin_model->select(array(),'','','','login_ip'), 'login_ip'));
|
||||
$ip_arr = array_merge($ip_arr, array_column($this->sys_admin_model->select(array(), '', '', '', 'login_ip'), 'login_ip'));
|
||||
if (!in_array($ip, $ip_arr)) {
|
||||
$check_view = true;
|
||||
$log = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$admin_info = array(
|
||||
'id' => $admin_user['id'],
|
||||
'username' => $admin_user['username'],
|
||||
'role_id' => $admin_user['role_id'],
|
||||
'login_ip' => $ip,
|
||||
);
|
||||
|
||||
$http_host = explode(':',$_SERVER['HTTP_HOST']);
|
||||
$http_host = explode(':', $_SERVER['HTTP_HOST']);
|
||||
$domain = explode('.', $http_host[0]);
|
||||
array_shift($domain);
|
||||
$domain = implode('.', $domain);
|
||||
|
||||
$this->input->set_cookie(LOGIN_COOKIE, $this->encryption->encrypt(json_encode($admin_info)), 86400 * 30, $domain);
|
||||
|
||||
if ($check_view) {
|
||||
if ($log == 1) {
|
||||
$this->load->model('sys/sys_admin_log_model');
|
||||
$log = array(
|
||||
'admin_id' => $admin_user['id'],
|
||||
@@ -111,13 +102,11 @@ class Login extends CI_Controller
|
||||
'jsondata' => json_encode($this->input->post(), JSON_UNESCAPED_UNICODE),
|
||||
);
|
||||
$this->sys_admin_log_model->add($log);
|
||||
|
||||
}
|
||||
if ($check_view) {
|
||||
return $this->show_json(SYS_CODE_SUCCESS, '访问IP发生变化,需要手机验证登录', '/login/check_view');
|
||||
|
||||
} else {
|
||||
|
||||
$this->sys_admin_model->update(array('login_ip' => $ip), array('id' => $admin_user['id']));
|
||||
|
||||
return $this->show_json(SYS_CODE_SUCCESS, ' 登 录 成 功', '/');
|
||||
}
|
||||
}
|
||||
@@ -214,7 +203,7 @@ class Login extends CI_Controller
|
||||
array_shift($domain);
|
||||
$domain = implode('.', $domain);
|
||||
|
||||
$this->input->set_cookie(LOGIN_COOKIE, '', 0 ,$domain);
|
||||
$this->input->set_cookie(LOGIN_COOKIE, '', 0, $domain);
|
||||
|
||||
return $this->show_json(SYS_CODE_SUCCESS, '注销成功', '/login');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user