From 02513188bf7996dbd4fc9ca183373d00e9bb6925 Mon Sep 17 00:00:00 2001 From: lijiaqi Date: Tue, 26 Dec 2023 14:51:16 +0800 Subject: [PATCH] update --- .../system/service/impl/AuthServiceImpl.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/ydool/system/service/impl/AuthServiceImpl.java b/src/main/java/com/ydool/system/service/impl/AuthServiceImpl.java index 1fbbebe..3bbdd78 100644 --- a/src/main/java/com/ydool/system/service/impl/AuthServiceImpl.java +++ b/src/main/java/com/ydool/system/service/impl/AuthServiceImpl.java @@ -76,7 +76,8 @@ public class AuthServiceImpl extends BaseService implements IA String captchaCache = (String) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE, captchaId); if (!captcha.equalsIgnoreCase(captchaCache)) { //获取IP失败次数 - Integer failCount = (Integer) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + String cache = (String) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + Integer failCount = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache) ; if (ObjectUtil.isNull(failCount)) { failCount = 1; } else { @@ -101,7 +102,8 @@ public class AuthServiceImpl extends BaseService implements IA User loginUser = getOne(new QueryWrapper().lambda().eq(User::getLoginName, userName)); if (ObjectUtil.isNull(loginUser)) { //获取IP失败次数 - Integer failCount = (Integer) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + String cache = (String) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + Integer failCount = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache) ; if (ObjectUtil.isNull(failCount)) { failCount = 1; } else { @@ -118,7 +120,8 @@ public class AuthServiceImpl extends BaseService implements IA //与数据库的密码进行匹配 if (!loginPassword.equals(loginUser.getPassword())) { //获取IP失败次数 - Integer failCount = (Integer) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + String cache = (String) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + Integer failCount = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache) ; if (ObjectUtil.isNull(failCount)) { failCount = 1; } else { @@ -133,7 +136,8 @@ public class AuthServiceImpl extends BaseService implements IA //判断账号是否停用 if (!loginUser.getStatus()) { //获取IP失败次数 - Integer failCount = (Integer) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + String cache = (String) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + Integer failCount = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache) ; if (ObjectUtil.isNull(failCount)) { failCount = 1; } else { @@ -149,7 +153,8 @@ public class AuthServiceImpl extends BaseService implements IA //判断账号角色 if (StrUtil.isBlank(loginUser.getRoles())) { //获取IP失败次数 - Integer failCount = (Integer) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + String cache = (String) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + Integer failCount = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache) ; if (ObjectUtil.isNull(failCount)) { failCount = 1; } else { @@ -164,7 +169,8 @@ public class AuthServiceImpl extends BaseService implements IA List roleList = userService.roleListByUser(loginUser.getId()); if (CollUtil.isEmpty(roleList)) { //获取IP失败次数 - Integer failCount = (Integer) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + String cache = (String) redisUtils.getMapCache(RedissonConstant.LOGIN_FAIL_COUNT, ip); + Integer failCount = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache) ; if (ObjectUtil.isNull(failCount)) { failCount = 1; } else { @@ -294,8 +300,9 @@ public class AuthServiceImpl extends BaseService implements IA public AjaxResult captcha() { //获取请求IP String ip = HttpServletUtil.getRemoteAddress(); - Integer count = (Integer) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE_COUNT, ip); - if (count != null && count > 5) { + String cache = (String) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE_COUNT, ip); + Integer count = ObjectUtil.isNull(cache)? 0 : Integer.valueOf(cache); + if (count != null && count > 60) { redisUtils.putMapCache(RedissonConstant.CAPTCHA_CODE_COUNT, ip, count + 1, 1, TimeUnit.MINUTES); return AjaxResult.fail("验证码获取频繁,请稍后再试"); }