lyhzzz 2 years ago
parent
commit
e9461bb027

+ 1 - 0
src/main/java/com/fdkankan/fusion/common/ResultCode.java

@@ -25,6 +25,7 @@ public enum ResultCode {
     RAND_ERROR(4021,"访问密码只能是4位字母或数字"),
     RAND_NOT_EXIST(4022,"访问密码为生成"),
     LOGIN_AUTH_NOT_EXIST(4023,"验证码不正确"),
+    LOGIN_AUTH_ERROR(4024,"验证码获取过于频繁请稍后"),
 
     USER_HAVE_CAMERA(6000,"该用户已绑定相机,请先绑定至其他用户,再修改该用户所属架构。"),
     DEPT_NAME_EXITS(6001,"部门名称已存在"),

+ 17 - 1
src/main/java/com/fdkankan/fusion/controller/NoLoginController.java

@@ -2,9 +2,11 @@ package com.fdkankan.fusion.controller;
 
 import cn.hutool.captcha.CaptchaUtil;
 import cn.hutool.captcha.LineCaptcha;
+import com.fdkankan.fusion.common.ResultCode;
 import com.fdkankan.fusion.common.ResultData;
 import com.fdkankan.fusion.common.util.RedisKeyUtil;
 import com.fdkankan.fusion.common.util.StringUtils;
+import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.response.UserAddRequest;
 import com.fdkankan.fusion.service.ITmUserService;
 import com.fdkankan.redis.util.RedisUtil;
@@ -12,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 @RestController
@@ -25,9 +28,22 @@ public class NoLoginController {
     ITmUserService tmUserService;
 
     @GetMapping("/getLoginAuthCode")
-    public void  getLoginCode(HttpServletResponse response){
+    public void  getLoginCode(HttpServletRequest request, HttpServletResponse response){
         response.setHeader("Cache-Control", "no-store, no-cache");
         response.setContentType("image/jpeg");
+        String sessionId = request.getSession().getId();
+
+        log.info("request--sessionId:{}",sessionId);
+        if(redisUtil.hasKey(sessionId)){
+            String value = redisUtil.get(sessionId);
+            String newValue = value +"1";
+            if(newValue.equals("11111")){
+                throw new BusinessException(ResultCode.LOGIN_AUTH_ERROR);
+            }
+            redisUtil.set(sessionId,value +"1",60);
+        }else {
+            redisUtil.set(sessionId, "1",60);
+        }
 
         try {
             LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);