Files
swiftadmin/app/admin/controller/Login.php

61 lines
1.6 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
namespace app\admin\controller;
2023-07-03 10:08:34 +08:00
use app\admin\service\LoginService;
use app\common\exception\OperateException;
2022-11-28 19:11:12 +08:00
use support\Response;
2022-08-19 19:48:37 +08:00
use app\AdminController;
use app\common\model\system\Admin;
2022-08-22 19:07:32 +08:00
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
2022-08-19 19:48:37 +08:00
class Login extends AdminController
{
/**
* 初始化方法
2022-08-22 19:07:32 +08:00
* @return void
2022-08-19 19:48:37 +08:00
* @throws \Exception
*/
public function __construct()
{
parent::__construct();
$this->model = new Admin();
$this->JumpUrl = '/admin/index';
}
/**
* 登录函数
2022-08-22 19:07:32 +08:00
* @return Response
2023-07-03 10:08:34 +08:00
* @throws OperateException
2022-08-22 19:07:32 +08:00
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
2022-08-19 19:48:37 +08:00
*/
2023-07-03 10:08:34 +08:00
public function index(): Response
2022-08-19 19:48:37 +08:00
{
// 禁止重复访问
2023-07-03 10:08:34 +08:00
$adminInfo = get_admin_info();
if (isset($adminInfo['id'])) {
2022-08-19 19:48:37 +08:00
return $this->redirect('/admin/index');
}
if (request()->isPost()) {
$user = request()->post('name');
$pwd = request()->post('pwd');
$captcha = request()->post('captcha');
2023-07-03 10:08:34 +08:00
validate(\app\common\validate\system\Admin::class)->scene('login')->check([
'name' => $user,
'pwd' => $pwd,
]);
2022-08-19 19:48:37 +08:00
2023-07-03 10:08:34 +08:00
LoginService::accountLogin($user, $pwd, $captcha, $adminInfo);
return $this->success('登录成功!', $this->JumpUrl);
2022-08-19 19:48:37 +08:00
}
return view('login/index', [
'captcha' => $session['isCaptcha'] ?? false,
2022-08-19 19:48:37 +08:00
]);
}
}