diff --git a/talk-db-proxy/src/main/java/com/blt/talk/service/redis/RedisKeys.java b/talk-db-proxy/src/main/java/com/blt/talk/service/redis/RedisKeys.java index f3c611d..f0176ab 100644 --- a/talk-db-proxy/src/main/java/com/blt/talk/service/redis/RedisKeys.java +++ b/talk-db-proxy/src/main/java/com/blt/talk/service/redis/RedisKeys.java @@ -19,6 +19,8 @@ public abstract class RedisKeys { /** 用户信息(Map) */ public static String USER_INFO = "usr"; + /** 用户临时信息-密码错误 */ + public static String USER_LOGIN_FAILD = "ulf"; /** 用户信息:用户未读 */ public static String USER_UNREAD = "unr"; diff --git a/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/LoginServiceController.java b/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/LoginServiceController.java index dad4653..9554262 100644 --- a/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/LoginServiceController.java +++ b/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/LoginServiceController.java @@ -5,12 +5,14 @@ package com.blt.talk.service.remote.impl; import java.util.List; +import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.HashOperations; import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.data.redis.core.ValueOperations; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; @@ -64,6 +66,16 @@ public class LoginServiceController implements LoginService { public BaseModel login(@RequestBody LoginReq param) { BaseModel userRes = new BaseModel<>(); + String key = RedisKeys.concat(RedisKeys.USER_LOGIN_FAILD, param.getName()); + ValueOperations faildCountOps = redisTemplate.opsForValue(); + String faildCount = faildCountOps.get(key); + int faild = 0; + if (!StringUtils.isEmpty(faildCount)) { + faild = Integer.parseInt(faildCount); + } + if (faild > 5) { + return userRes.setResult(LoginCmdResult.LOGIN_PASSWORD_LOCK); + } // 改为:用户名或手机号皆可登录 SearchCriteria userSearchCriteria = new SearchCriteria<>(); @@ -79,10 +91,6 @@ public class LoginServiceController implements LoginService { IMUser user = users.get(0); - // if (user.getStatus() == 0) { - // 判断用户状态 - // } - if (passwordEncoder.matches(param.getPassword(), user.getPassword())) { // 密码正确 UserEntity userEntity = new UserEntity(); @@ -103,11 +111,13 @@ public class LoginServiceController implements LoginService { userRes.setData(userEntity); // 如果登陆成功,则清除错误尝试限制 - + if (faild > 0) { + redisTemplate.delete(key); + } } else { // 密码错误,记录一次登陆失败 - + faildCountOps.set(key, String.valueOf(++faild), 30, TimeUnit.MINUTES); return userRes.setResult(LoginCmdResult.LOGIN_NOUSER); } return userRes; diff --git a/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/MessageServiceController.java b/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/MessageServiceController.java index 41d6344..5af7b79 100644 --- a/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/MessageServiceController.java +++ b/talk-db-proxy/src/main/java/com/blt/talk/service/remote/impl/MessageServiceController.java @@ -561,7 +561,8 @@ public class MessageServiceController implements MessageService { if (groupCount == null) { continue; } - String userCount = hashOptions.get(userKey, RedisKeys.concat(RedisKeys.GROUP_UNREAD, group)); + String userCount = + hashOptions.get(userKey, RedisKeys.concat(RedisKeys.GROUP_UNREAD, group.getGroupId())); Integer unreadCount = userCount != null ? Integer.valueOf(groupCount) - Integer.valueOf(userCount) : Integer.valueOf(groupCount);