From af378cf62ec96dbba1abb283dca815210b09aea3 Mon Sep 17 00:00:00 2001 From: ccfish86 Date: Tue, 6 Jun 2017 10:55:08 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E7=99=BB=E5=BD=95=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF=E6=AC=A1=E6=95=B0=E9=99=90=E5=88=B6?= =?UTF-8?q?=EF=BC=88=E8=BF=9E=E7=BB=AD=E9=94=99=E8=AF=AF6=E6=AC=A1?= =?UTF-8?q?=EF=BC=8C=E5=8D=8A=E5=B0=8F=E6=97=B6=E5=86=85=E7=A6=81=E6=AD=A2?= =?UTF-8?q?=E7=99=BB=E5=BD=95=EF=BC=89=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=89=8B?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/blt/talk/service/redis/RedisKeys.java | 2 ++ .../remote/impl/LoginServiceController.java | 22 ++++++++++++++----- .../remote/impl/MessageServiceController.java | 3 ++- 3 files changed, 20 insertions(+), 7 deletions(-) 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);