更新登录处理
This commit is contained in:
parent
0c72827b43
commit
faa1cdb9fa
|
@ -97,10 +97,15 @@ abstract class BaseController
|
||||||
protected function checkLogin()
|
protected function checkLogin()
|
||||||
{
|
{
|
||||||
$session_admin = get_config('app.session_admin');
|
$session_admin = get_config('app.session_admin');
|
||||||
if (!Session::has($session_admin)) {
|
$header = Request::header();
|
||||||
|
$token = $header['token'] ?? '';
|
||||||
|
if (!Session::has($session_admin) || !$token) {
|
||||||
$this->apiError('请先登录');
|
$this->apiError('请先登录');
|
||||||
}
|
}
|
||||||
else{
|
if ($token) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (Session::has($session_admin)) {
|
||||||
$this->uid = Session::get($session_admin);
|
$this->uid = Session::get($session_admin);
|
||||||
$login_admin = Db::name('Admin')->where(['id' => $this->uid])->find();
|
$login_admin = Db::name('Admin')->where(['id' => $this->uid])->find();
|
||||||
$this->did = $login_admin['did'];
|
$this->did = $login_admin['did'];
|
||||||
|
|
|
@ -46,16 +46,17 @@ class Login
|
||||||
if ($admin['status'] != 1) {
|
if ($admin['status'] != 1) {
|
||||||
return to_assign(1, '该用户禁止登录,请与管理者联系');
|
return to_assign(1, '该用户禁止登录,请与管理者联系');
|
||||||
}
|
}
|
||||||
|
$token = make_token();
|
||||||
$data = [
|
$data = [
|
||||||
'is_lock' => 0,
|
'is_lock' => 0,
|
||||||
'last_login_time' => time(),
|
'last_login_time' => time(),
|
||||||
'last_login_ip' => request()->ip(),
|
'last_login_ip' => request()->ip(),
|
||||||
'login_num' => $admin['login_num'] + 1,
|
'login_num' => $admin['login_num'] + 1,
|
||||||
|
'token' => $token
|
||||||
];
|
];
|
||||||
Db::name('admin')->where(['id' => $admin['id']])->update($data);
|
Db::name('admin')->where(['id' => $admin['id']])->update($data);
|
||||||
$session_admin = get_config('app.session_admin');
|
$session_admin = get_config('app.session_admin');
|
||||||
Session::set($session_admin, $admin['id']);
|
Session::set($session_admin, $admin['id']);
|
||||||
$token = make_token();
|
|
||||||
set_cache($token, $admin, 7200);
|
set_cache($token, $admin, 7200);
|
||||||
$admin['token'] = $token;
|
$admin['token'] = $token;
|
||||||
$logdata = [
|
$logdata = [
|
||||||
|
@ -69,7 +70,7 @@ class Login
|
||||||
'create_time' => time()
|
'create_time' => time()
|
||||||
];
|
];
|
||||||
Db::name('AdminLog')->strict(false)->field(true)->insert($logdata);
|
Db::name('AdminLog')->strict(false)->field(true)->insert($logdata);
|
||||||
return to_assign(0, '登录成功', ['uid' => $admin['id']]);
|
return to_assign(0, '登录成功', ['uid' => $admin['id'], 'token' => $token]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//退出登录
|
//退出登录
|
||||||
|
|
|
@ -14,7 +14,7 @@ class UserCheck extends Validate
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'username' => 'require',
|
'username' => 'require',
|
||||||
'password' => 'require',
|
'password' => 'require',
|
||||||
'captcha' => 'require|captcha',
|
'captcha' => 'captcha',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $message = [
|
protected $message = [
|
||||||
|
|
Loading…
Reference in New Issue