diff --git a/app/common/service/AuthService.php b/app/common/service/AuthService.php index fa0660a..f360bba 100644 --- a/app/common/service/AuthService.php +++ b/app/common/service/AuthService.php @@ -24,7 +24,7 @@ class AuthService } if ($user['status'] != 1) { - throw new \Exception('账户已禁用'); + throw new \Exception('账户已禁用,请联系管理员'); } diff --git a/app/common/service/TicketService.php b/app/common/service/TicketService.php index 94ef87f..9befeb0 100644 --- a/app/common/service/TicketService.php +++ b/app/common/service/TicketService.php @@ -57,7 +57,10 @@ class TicketService /** - * 新增工单 + * 创建工单业务逻辑 + * @param array $data 工单数据 + * @return Tickets + * @throws \Exception */ public function createTicket(array $data) { diff --git a/app/index/controller/Login.php b/app/index/controller/Login.php index 658d126..9e510a9 100644 --- a/app/index/controller/Login.php +++ b/app/index/controller/Login.php @@ -9,7 +9,7 @@ use think\facade\Session; // 已完成 class Login extends BaseController -{ +{ /* 处理登录请求(已完成) */ @@ -17,15 +17,24 @@ class Login extends BaseController { $params = $this->request->only(['username', 'password'], 'post'); - // 验证数据 - if (empty($params['username']) || empty($params['password'])) { + if (empty(trim($params['username'])) || empty(trim($params['password']))) { // 验证数据 return $this->error('用户名和密码不能为空'); } + $username = trim($params['username']); + $failKey = 'login_fail_' . md5($username); + $fails = (int) cache($failKey); // 读取失败次数,并强制转为整数 + + if ($fails >= 5) { + return $this->error('失败次数过多,请 15 分钟后再试', [], 429); + } + try { - $result = $authService->login($params['username'], $params['password']); + $result = $authService->login(trim($params['username']), trim($params['password'])); + cache($failKey, null); return $this->success('登录成功', $result); } catch (\Exception $e) { + cache($failKey, $fails + 1, 900); // 失败次数存活时间,15分钟之后自动清零 return $this->error($e->getMessage()); } }