清理技术债务;增加后台登录成功事件;

This commit is contained in:
2023-09-09 13:43:29 +08:00
parent 1b0ae546c3
commit a2c14391b1
5 changed files with 55 additions and 23 deletions

View File

@@ -1,23 +1,20 @@
<?php
namespace app\admin\controller;
use app\admin\model\SystemAdmin;
use app\common\controller\AdminController;
use think\captcha\facade\Captcha;
use think\facade\Env;
use think\facade\Event;
/**
* Class Login
* @package app\admin\controller
* Class Login.
*/
class Login extends AdminController
{
/**
* 初始化方法
* 初始化方法.
*/
public function initialize()
{
@@ -30,7 +27,7 @@ class Login extends AdminController
}
/**
* 用户登录
* 用户登录.
* @return string
* @throws \Exception
*/
@@ -40,8 +37,8 @@ class Login extends AdminController
if ($this->request->isPost()) {
$post = $this->request->post();
$rule = [
'username|用户名' => 'require',
'password|密码' => 'require',
'username|用户名' => 'require',
'password|密码' => 'require',
'keep_login|是否保持登录' => 'require',
];
$captcha == 1 && $rule['captcha|验证码'] = 'require|captcha';
@@ -58,19 +55,24 @@ class Login extends AdminController
}
$admin->login_num += 1;
$admin->save();
Event::trigger('AdminLoginSuccess', $admin);
$admin = $admin->toArray();
unset($admin['password']);
$admin['expire_time'] = $post['keep_login'] == 1 ? true : time() + 7200;
session('admin', $admin);
$this->success('登录成功');
}
$this->assign('captcha', $captcha);
$this->assign('demo', $this->isDemo);
return $this->fetch();
}
/**
* 用户退出
* 用户退出.
* @return mixed
*/
public function out()

View File

@@ -1,17 +1,14 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
'AppInit' => [
\app\admin\listener\ViewInitListener::class,
],
'HttpRun' => [
\app\admin\listener\ViewInitListener::class,
],
'HttpEnd' => [],
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
],