Explorar el Código

feat: 修改管理员登陆提示错误信息.

zhangl hace 1 año
padre
commit
89647197da
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      backendApi/modules/v1/models/LoginForm.php

+ 12 - 0
backendApi/modules/v1/models/LoginForm.php

@@ -88,6 +88,8 @@ class LoginForm extends Model {
         if(isset($this->_user)){
         if(isset($this->_user)){
             AdminLoginLogger::fail($this->_user,$returnResult);
             AdminLoginLogger::fail($this->_user,$returnResult);
         }
         }
+        // 失败写入缓存锁
+        Yii::$app->redis->incrby('FAIL_NUMS:' . $this->adminName, 1);
     }
     }
 
 
     /**
     /**
@@ -97,6 +99,9 @@ class LoginForm extends Model {
         Admin::updateAllCounters([
         Admin::updateAllCounters([
             'LOGIN_NUMS' => 1,
             'LOGIN_NUMS' => 1,
         ], 'ADMIN_NAME=:ADMIN_NAME', ['ADMIN_NAME' => $this->adminName]);
         ], 'ADMIN_NAME=:ADMIN_NAME', ['ADMIN_NAME' => $this->adminName]);
+
+        // 失败写入缓存锁
+        Yii::$app->redis->delete('FAIL_NUMS:' . $this->adminName);
     }
     }
     /**
     /**
      * 登录
      * 登录
@@ -114,6 +119,13 @@ class LoginForm extends Model {
             if(!$this->_user){
             if(!$this->_user){
                 throw new Exception('账号不存在');
                 throw new Exception('账号不存在');
             }
             }
+            // 失败次数到达上限次数
+            $loginFailNums = Yii::$app->redis->get('FAIL_NUMS:' . $this->adminName) ?? 0;
+            if ($loginFailNums >= 3) {
+                $this->_updateFailTimes($transaction,'用户名或者密码错误');
+                throw new Exception('用户名或者密码错误');
+            }
+
             if(!$this->_user['IS_ENABLE']){
             if(!$this->_user['IS_ENABLE']){
                 $this->_updateFailTimes($transaction,'账号已经被锁定,无法登录');
                 $this->_updateFailTimes($transaction,'账号已经被锁定,无法登录');
                 throw new Exception('用户名或者密码错误');
                 throw new Exception('用户名或者密码错误');