|
@@ -2,6 +2,8 @@ package com.fdkankan.fusion.controller;
|
|
|
|
|
|
import cn.hutool.captcha.CaptchaUtil;
|
|
|
import cn.hutool.captcha.LineCaptcha;
|
|
|
+import cn.hutool.http.ContentType;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
|
import com.fdkankan.fusion.common.ResultData;
|
|
|
import com.fdkankan.fusion.common.util.RedisKeyUtil;
|
|
@@ -11,11 +13,14 @@ import com.fdkankan.fusion.response.UserAddRequest;
|
|
|
import com.fdkankan.fusion.service.ITmUserService;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpHeaders;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/notAuth")
|
|
@@ -28,9 +33,8 @@ public class NoLoginController {
|
|
|
ITmUserService tmUserService;
|
|
|
|
|
|
@GetMapping("/getLoginAuthCode")
|
|
|
- public void getLoginCode(HttpServletRequest request, HttpServletResponse response){
|
|
|
- response.setHeader("Cache-Control", "no-store, no-cache");
|
|
|
- response.setContentType("image/jpeg");
|
|
|
+ public void getLoginCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
+
|
|
|
String sessionId = request.getSession().getId();
|
|
|
|
|
|
log.info("request--sessionId:{}",sessionId);
|
|
@@ -38,13 +42,18 @@ public class NoLoginController {
|
|
|
String value = redisUtil.get(sessionId);
|
|
|
String newValue = value +"1";
|
|
|
if(newValue.equals("11111")){
|
|
|
- throw new BusinessException(ResultCode.LOGIN_AUTH_ERROR);
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.JSON.getValue());
|
|
|
+ response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
|
|
+ String result = JSONObject.toJSONString(ResultData.error(ResultCode.LOGIN_AUTH_ERROR));
|
|
|
+ response.getWriter().append(result);
|
|
|
}
|
|
|
redisUtil.set(sessionId,value +"1",60);
|
|
|
}else {
|
|
|
redisUtil.set(sessionId, "1",60);
|
|
|
}
|
|
|
|
|
|
+ response.setHeader("Cache-Control", "no-store, no-cache");
|
|
|
+ response.setContentType("image/jpeg");
|
|
|
try {
|
|
|
LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
|
|
|
while (redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,lineCaptcha.getCode()))){
|