This commit is contained in:
lijiaqi 2023-12-26 14:51:16 +08:00
parent 373d9f2316
commit 02513188bf
1 changed files with 15 additions and 8 deletions

View File

@ -76,7 +76,8 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
String captchaCache = (String) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE, captchaId); String captchaCache = (String) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE, captchaId);
if (!captcha.equalsIgnoreCase(captchaCache)) { if (!captcha.equalsIgnoreCase(captchaCache)) {
//获取IP失败次数 //获取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)) { if (ObjectUtil.isNull(failCount)) {
failCount = 1; failCount = 1;
} else { } else {
@ -101,7 +102,8 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
User loginUser = getOne(new QueryWrapper<User>().lambda().eq(User::getLoginName, userName)); User loginUser = getOne(new QueryWrapper<User>().lambda().eq(User::getLoginName, userName));
if (ObjectUtil.isNull(loginUser)) { if (ObjectUtil.isNull(loginUser)) {
//获取IP失败次数 //获取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)) { if (ObjectUtil.isNull(failCount)) {
failCount = 1; failCount = 1;
} else { } else {
@ -118,7 +120,8 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
//与数据库的密码进行匹配 //与数据库的密码进行匹配
if (!loginPassword.equals(loginUser.getPassword())) { if (!loginPassword.equals(loginUser.getPassword())) {
//获取IP失败次数 //获取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)) { if (ObjectUtil.isNull(failCount)) {
failCount = 1; failCount = 1;
} else { } else {
@ -133,7 +136,8 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
//判断账号是否停用 //判断账号是否停用
if (!loginUser.getStatus()) { if (!loginUser.getStatus()) {
//获取IP失败次数 //获取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)) { if (ObjectUtil.isNull(failCount)) {
failCount = 1; failCount = 1;
} else { } else {
@ -149,7 +153,8 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
//判断账号角色 //判断账号角色
if (StrUtil.isBlank(loginUser.getRoles())) { if (StrUtil.isBlank(loginUser.getRoles())) {
//获取IP失败次数 //获取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)) { if (ObjectUtil.isNull(failCount)) {
failCount = 1; failCount = 1;
} else { } else {
@ -164,7 +169,8 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
List<Role> roleList = userService.roleListByUser(loginUser.getId()); List<Role> roleList = userService.roleListByUser(loginUser.getId());
if (CollUtil.isEmpty(roleList)) { //获取IP失败次数 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)) { if (ObjectUtil.isNull(failCount)) {
failCount = 1; failCount = 1;
} else { } else {
@ -294,8 +300,9 @@ public class AuthServiceImpl extends BaseService<UserMapper, User> implements IA
public AjaxResult captcha() { public AjaxResult captcha() {
//获取请求IP //获取请求IP
String ip = HttpServletUtil.getRemoteAddress(); String ip = HttpServletUtil.getRemoteAddress();
Integer count = (Integer) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE_COUNT, ip); String cache = (String) redisUtils.getMapCache(RedissonConstant.CAPTCHA_CODE_COUNT, ip);
if (count != null && count > 5) { 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); redisUtils.putMapCache(RedissonConstant.CAPTCHA_CODE_COUNT, ip, count + 1, 1, TimeUnit.MINUTES);
return AjaxResult.fail("验证码获取频繁,请稍后再试"); return AjaxResult.fail("验证码获取频繁,请稍后再试");
} }