Update Login.php

This commit is contained in:
Anyon 2019-09-23 11:43:46 +08:00
parent 8e6c15e485
commit dae44ab087

View File

@ -18,6 +18,7 @@ namespace app\admin\controller;
use app\admin\service\NodeService; use app\admin\service\NodeService;
use library\Controller; use library\Controller;
use think\Db; use think\Db;
use think\facade\Request;
/** /**
* 用户登录管理 * 用户登录管理
@ -37,30 +38,26 @@ class Login extends Controller
*/ */
public function index() public function index()
{ {
$this->title = '系统登录'; if (Request::isGet()) {
if ($this->request->isGet()) {
// 运行环境检查
$this->devMode = in_array($this->request->rootDomain(), [
'0.1', 'localhost', 'thinkadmin.top', 'ctolog.com',
]);
// 登录状态检查 // 登录状态检查
if (NodeService::islogin()) { if (NodeService::islogin()) {
// 已经登录,跳转到后面首页
$this->redirect('@admin'); $this->redirect('@admin');
} else { } else {
$this->loginskey = session('loginskey'); // 定义运行环境模式
if (empty($this->loginskey)) { $this->domain = Request::host(true);
$this->loginskey = uniqid(); $this->devmode = in_array($this->domain, ['127.0.0.1', 'localhost']) or stripos($this->domain, 'thinkadmin.top') <> false;
session('loginskey', $this->loginskey); // 创建登录安全通道
} if (!($this->loginskey = session('loginskey'))) session('loginskey', $this->loginskey = uniqid());
// 显示后台登录页面
$this->title = '系统登录';
$this->fetch(); $this->fetch();
} }
} else { } else {
$data = $this->_input([ $data = $this->_input([
'username' => $this->request->post('username'), 'username' => input('username'), 'password' => input('password'),
'password' => $this->request->post('password'),
], [ ], [
'username' => 'require|min:4', 'username' => 'require|min:4', 'password' => 'require|min:4',
'password' => 'require|min:4',
], [ ], [
'username.require' => '登录账号不能为空!', 'username.require' => '登录账号不能为空!',
'password.require' => '登录密码不能为空!', 'password.require' => '登录密码不能为空!',
@ -98,13 +95,15 @@ class Login extends Controller
// 登录成功并更新账号 // 登录成功并更新账号
cache("user_login_{$user['username']}", null); cache("user_login_{$user['username']}", null);
Db::name('SystemUser')->where(['id' => $user['id']])->update([ 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('loginskey', null); session('loginskey', null);
session('admin_user', $user); session('admin_user', $user);
NodeService::applyUserAuth(); NodeService::applyUserAuth(true);
sysoplog('系统管理', '用户登录系统成功'); sysoplog('系统管理', '用户登录系统成功');
$this->success('登录成功,正在进入系统...', url('@admin')); $this->success('登录成功', url('@admin'));
} }
} }