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).'次机会');