From 5eca489b1cdd984978e5932af63fc69aa2f4e5d3 Mon Sep 17 00:00:00 2001 From: lq Date: Wed, 4 Dec 2024 14:19:43 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=AC=A1=E6=95=B0=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/controllers/LoginController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/admin/controllers/LoginController.php b/admin/controllers/LoginController.php index bd3e187..0366c13 100644 --- a/admin/controllers/LoginController.php +++ b/admin/controllers/LoginController.php @@ -31,8 +31,9 @@ class LoginController extends BaseAdminController $expireTime = 1800; // 30 分钟 $redis = Yii::$app->redis; $errNum = $redis->get($key); + $txt = '当前账号因频繁登录失败已被锁定,30分钟内无法重试,预计解锁时间:'; if ($errNum >= $maxAttempts) { - throw new Exception("当前账号因频繁登录已被锁定,30分钟内无法重试,预计解锁时间:". date('Y-m-d H:i:s', time() + $redis->ttl($key))); + throw new Exception($txt. date('Y-m-d H:i:s', time() + $redis->ttl($key))); } $model = new LoginForm(); @@ -82,9 +83,9 @@ class LoginController extends BaseAdminController $currentValue = $redis->incr($key); // 如果是第一次累加,设置过期时间 - if ($currentValue == 5) { + if (in_array($currentValue, [1, 5])) { $redis->expire($key, $expireTime); - throw new Exception("当前账号因频繁登录已被锁定,30分钟内无法重试,预计解锁时间:". date('Y-m-d H:i:s', time() + $redis->ttl($key))); + throw new Exception($txt. date('Y-m-d H:i:s', time() + $redis->ttl($key))); } } throw new Exception($e->getMessage().' 还有'.($maxAttempts - $currentValue).'次机会');