[更新]修改后台登录

This commit is contained in:
Anyon 2019-04-04 10:34:31 +08:00
parent e8b38b65cc
commit 16d96c96fb
2 changed files with 53 additions and 61 deletions

View File

@ -24,12 +24,6 @@ use think\Db;
*/
class Login extends Controller
{
/**
* 设置页面标题
* @var string
*/
public $title = '管理登录';
/**
* 用户登录
* @throws \think\Exception
@ -40,11 +34,12 @@ class Login extends Controller
*/
public function index()
{
$this->title = '管理登录';
$this->applyCsrfToken();
if ($this->request->isGet()) {
session('loginskey', $this->skey = session('loginskey') ? session('loginskey') : uniqid());
$this->fetch();
} else {
return $this->fetch();
}
$data = $this->_input([
'username' => $this->request->post('username'),
'password' => $this->request->post('password'),
@ -59,9 +54,9 @@ class Login extends Controller
]);
// 用户信息验证
$map = ['is_deleted' => '0', 'username' => $data['username']];
$user = Db::name('SystemUser')->where($map)->find();
$user = Db::name('SystemUser')->where($map)->order('id desc')->find();
if (empty($user)) $this->error('登录账号或密码错误,请重新输入!');
if (empty($user['status'])) $this->error('账号已经被禁用,请联系管理!');
if (empty($user['status'])) $this->error('账号已经被禁用,请联系管理!');
// 账号锁定消息
$cache = cache("user_login_{$user['username']}");
if (is_array($cache) && !empty($cache['number']) && !empty($cache['time'])) {
@ -88,17 +83,14 @@ class Login extends Controller
// 登录成功并更新账号
cache("user_login_{$user['username']}", null);
Db::name('SystemUser')->where(['id' => $user['id']])->update([
'login_at' => Db::raw('now()'),
'login_ip' => $this->request->ip(),
'login_num' => Db::raw('login_num+1'),
'login_at' => Db::raw('now()'), 'login_ip' => $this->request->ip(), 'login_num' => Db::raw('login_num+1'),
]);
session('user', $user);
session('loginskey', null);
if (!empty($user['authorize'])) \app\admin\service\Auth::applyNode();
_syslog('系统管理', '用户登录系统成功');
empty($user['authorize']) || \app\admin\service\Auth::applyNode();
$this->success('登录成功,正在进入系统...', url('@admin'));
}
}
/**
* 退出登录

View File

@ -37,7 +37,7 @@ class Log
'geoip' => PHP_SAPI === 'cli' ? '127.0.0.1' : request()->ip(),
'action' => $action,
'content' => $content,
'username' => PHP_SAPI === 'cli' ? 'cli' : session('user.username'),
'username' => PHP_SAPI === 'cli' ? 'cli' : (string)session('user.username'),
];
return Db::name('SystemLog')->insert($data) !== false;
}