lyhzzz 9 months ago
parent
commit
e120048dfe
1 changed files with 16 additions and 8 deletions
  1. 16 8
      src/main/java/com/fdkankan/ucenter/controller/LoginController.java

+ 16 - 8
src/main/java/com/fdkankan/ucenter/controller/LoginController.java

@@ -52,11 +52,14 @@ public class LoginController extends BaseController {
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
         }
         String id = request.getSession().getId();
-        if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
+        String redisKey = String.format(RedisKeyUtil.loginAuthCode,id);
+        String redisCode = redisUtil.get(redisKey);
+        if(!redisUtil.hasKey(redisKey)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
         }
-        MathGenerator mathGenerator = new MathGenerator(3);
-        boolean verify = mathGenerator.verify(redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)),param.getAuthCode());
+        redisUtil.del(redisKey);
+        MathGenerator mathGenerator = new MathGenerator(2);
+        boolean verify = mathGenerator.verify(redisCode,param.getAuthCode());
         if(!verify){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
         }
@@ -106,15 +109,20 @@ public class LoginController extends BaseController {
         if(StringUtils.isBlank(param.getAuthCode())){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
         }
+
         String id = request.getSession().getId();
-        if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
+        String redisKey = String.format(RedisKeyUtil.loginAuthCode,id);
+        String redisCode = redisUtil.get(redisKey);
+        if(!redisUtil.hasKey(redisKey)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
         }
-        MathGenerator mathGenerator = new MathGenerator(3);
-        boolean verify = mathGenerator.verify(redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)),param.getAuthCode());
+        redisUtil.del(redisKey);
+        MathGenerator mathGenerator = new MathGenerator(2);
+        boolean verify = mathGenerator.verify(redisCode,param.getAuthCode());
         if(!verify){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3006, LoginConstant.FAILURE_MSG_3006);
         }
+
 //        if(redisUtil.hasKey(String.format(RedisKeyUtil.checkUserCount,id))){
 //            String countStr = redisUtil.get(String.format(RedisKeyUtil.checkUserCount, id));
 //            if(Integer.valueOf(countStr) >=5){
@@ -223,8 +231,8 @@ public class LoginController extends BaseController {
         response.setContentType("image/jpeg");
         String id = request.getSession().getId();
         try {
-            LineCaptcha lineCaptcha = new LineCaptcha(400, 100);
-            MathGenerator mathGenerator = new MathGenerator(3);
+            LineCaptcha lineCaptcha = new LineCaptcha(300, 100);
+            MathGenerator mathGenerator = new MathGenerator(2);
             lineCaptcha.setGenerator(mathGenerator);
             redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5);
             lineCaptcha.write(response.getOutputStream());