|
@@ -1,19 +1,31 @@
|
|
|
package com.fdkankan.manage.controller;
|
|
package com.fdkankan.manage.controller;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.captcha.CaptchaUtil;
|
|
|
|
|
+import cn.hutool.captcha.LineCaptcha;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.dtflys.forest.annotation.BaseRequest;
|
|
import com.dtflys.forest.annotation.BaseRequest;
|
|
|
|
|
+import com.fdkankan.manage.common.RedisKeyUtil;
|
|
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
import com.fdkankan.manage.common.ResultData;
|
|
import com.fdkankan.manage.common.ResultData;
|
|
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
import com.fdkankan.manage.service.impl.ManageService;
|
|
import com.fdkankan.manage.service.impl.ManageService;
|
|
|
import com.fdkankan.manage.vo.request.ManageLoginRequest;
|
|
import com.fdkankan.manage.vo.request.ManageLoginRequest;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 登录 登出
|
|
* 登录 登出
|
|
|
*/
|
|
*/
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/service/manage/")
|
|
@RequestMapping("/service/manage/")
|
|
|
|
|
+@Slf4j
|
|
|
public class LoginController extends BaseController {
|
|
public class LoginController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
@@ -25,6 +37,17 @@ public class LoginController extends BaseController {
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("/login")
|
|
@PostMapping("/login")
|
|
|
public ResultData login(@RequestBody ManageLoginRequest param) {
|
|
public ResultData login(@RequestBody ManageLoginRequest param) {
|
|
|
|
|
+ if(StringUtils.isBlank(param.getAuthCode())){
|
|
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
|
|
+ }
|
|
|
|
|
+ String id = request.getSession().getId();
|
|
|
|
|
+ if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
|
|
|
|
|
+ throw new BusinessException(ResultCode.LOGIN_AUTH_NOT_EXIST);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)).equals(param.getAuthCode())){
|
|
|
|
|
+ throw new BusinessException(ResultCode.LOGIN_AUTH_NOT_EXIST);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
String clientIP = ServletUtil.getClientIP(request);
|
|
String clientIP = ServletUtil.getClientIP(request);
|
|
|
return ResultData.ok(manageService.login(clientIP,param.getUserName(),param.getPassword()));
|
|
return ResultData.ok(manageService.login(clientIP,param.getUserName(),param.getPassword()));
|
|
|
}
|
|
}
|
|
@@ -36,5 +59,23 @@ public class LoginController extends BaseController {
|
|
|
manageService.logout();
|
|
manageService.logout();
|
|
|
return ResultData.ok();
|
|
return ResultData.ok();
|
|
|
}
|
|
}
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/getLoginAuthCode")
|
|
|
|
|
+ public void getLoginCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
|
|
+ response.setHeader("Cache-Control", "no-store, no-cache");
|
|
|
|
|
+ response.setContentType("image/jpeg");
|
|
|
|
|
+ String id = request.getSession().getId();
|
|
|
|
|
+ try {
|
|
|
|
|
+ LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
|
|
|
|
|
+ redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5);
|
|
|
|
|
+ lineCaptcha.write(response.getOutputStream());
|
|
|
|
|
+ response.getOutputStream().close();
|
|
|
|
|
+ } catch (Exception e){
|
|
|
|
|
+ log.info("生成登录验证码错误:",e);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|