dev #1
@@ -24,7 +24,7 @@ class AuthService
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($user['status'] != 1) {
|
if ($user['status'] != 1) {
|
||||||
throw new \Exception('账户已禁用');
|
throw new \Exception('账户已禁用,请联系管理员');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,10 @@ class TicketService
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增工单
|
* 创建工单业务逻辑
|
||||||
|
* @param array $data 工单数据
|
||||||
|
* @return Tickets
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function createTicket(array $data)
|
public function createTicket(array $data)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use think\facade\Session;
|
|||||||
|
|
||||||
// 已完成
|
// 已完成
|
||||||
class Login extends BaseController
|
class Login extends BaseController
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
处理登录请求(已完成)
|
处理登录请求(已完成)
|
||||||
*/
|
*/
|
||||||
@@ -17,15 +17,24 @@ class Login extends BaseController
|
|||||||
{
|
{
|
||||||
$params = $this->request->only(['username', 'password'], 'post');
|
$params = $this->request->only(['username', 'password'], 'post');
|
||||||
|
|
||||||
// 验证数据
|
if (empty(trim($params['username'])) || empty(trim($params['password']))) { // 验证数据
|
||||||
if (empty($params['username']) || empty($params['password'])) {
|
|
||||||
return $this->error('用户名和密码不能为空');
|
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 {
|
try {
|
||||||
$result = $authService->login($params['username'], $params['password']);
|
$result = $authService->login(trim($params['username']), trim($params['password']));
|
||||||
|
cache($failKey, null);
|
||||||
return $this->success('登录成功', $result);
|
return $this->success('登录成功', $result);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
cache($failKey, $fails + 1, 900); // 失败次数存活时间,15分钟之后自动清零
|
||||||
return $this->error($e->getMessage());
|
return $this->error($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user