Browse Source

登录日志处理

yq 3 years ago
parent
commit
ea6856430b

+ 20 - 0
src/main/java/com/usky/dxtop/framework/web/service/SysLoginService.java

@@ -102,6 +102,7 @@ public class SysLoginService
         LoginUser loginUser = (LoginUser) authentication.getPrincipal();
         LoginUser loginUser = (LoginUser) authentication.getPrincipal();
         recordLoginInfo(loginUser.getUser());
         recordLoginInfo(loginUser.getUser());
         // 生成token
         // 生成token
+        checkAccount(username);
         return tokenService.createToken(loginUser);
         return tokenService.createToken(loginUser);
     }
     }
 
 
@@ -174,6 +175,25 @@ public class SysLoginService
         }
         }
     }
     }
 
 
+    /**
+     * 登录成功后判断是否达到了密码限制
+     * @param userName
+     */
+    public void checkAccount(String userName){
+        AccountLock accountLock = accountLockService.isEnableOne();
+        if (null != accountLock){
+            Object cacheObj = redisCache.getCacheObject(getLockAccountKey(userName));
+            if (Objects.nonNull(cacheObj)) {
+                UserAccountVO userAccountVO = (UserAccountVO) cacheObj;
+                if (userAccountVO.getTotalCount() > userAccountVO.getUseCount()){
+                    redisCache.deleteObject(getLockAccountKey(userName));
+                } else {
+                    throw new CustomException(userAccountVO.getTotalCount()+"次机会已经用完,账号被锁定"+accountLock.getLoseDate()+"分钟");
+                }
+            }
+        }
+    }
+
     public String getLockAccountKey(String userName){
     public String getLockAccountKey(String userName){
         return UserConstants.ACCOUNT_LOCK + "_" + userName;
         return UserConstants.ACCOUNT_LOCK + "_" + userName;
     }
     }