refactor: captcha-plus

pull/2/head
xingyu 2023-01-16 11:12:30 +08:00
parent fffe3008b5
commit 860b0301b7
2 changed files with 23 additions and 7 deletions

View File

@ -41,7 +41,7 @@
<!-- Bpm 工作流相关 --> <!-- Bpm 工作流相关 -->
<flowable.version>6.8.0</flowable.version> <flowable.version>6.8.0</flowable.version>
<!-- 工具类相关 --> <!-- 工具类相关 -->
<captcha-plus.version>0.0.1</captcha-plus.version> <captcha-plus.version>1.0.0</captcha-plus.version>
<jsoup.version>1.15.3</jsoup.version> <jsoup.version>1.15.3</jsoup.version>
<lombok.version>1.18.24</lombok.version> <lombok.version>1.18.24</lombok.version>
<mapstruct.version>1.5.3.Final</mapstruct.version> <mapstruct.version>1.5.3.Final</mapstruct.version>

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.system.controller.admin.captcha; package cn.iocoder.yudao.module.system.controller.admin.captcha;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import com.anji.captcha.model.common.ResponseModel; import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO; import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -10,28 +13,31 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll; import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
/** /**
* *
* *
* 使 anji CaptchaController
* 使 /admin-api/*
*
* @author * @author
*/ */
@Api(tags = "管理后台 - 验证码") @Api(tags = "管理后台 - 验证码")
@RestController("adminCaptchaController") @RestController("adminCaptchaController")
@RequestMapping("/system/captcha") @RequestMapping("/system/captcha")
public class CaptchaController extends com.anji.captcha.controller.CaptchaController { public class CaptchaController {
@Resource
private CaptchaService captchaService;
@PostMapping({"/get"}) @PostMapping({"/get"})
@ApiOperation("获得验证码") @ApiOperation("获得验证码")
@PermitAll @PermitAll
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志 @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) { public ResponseModel get(@RequestBody CaptchaVO data, HttpServletRequest request) {
return super.get(data, request); assert request.getRemoteHost() != null;
data.setBrowserInfo(getRemoteId(request));
return captchaService.get(data);
} }
@PostMapping("/check") @PostMapping("/check")
@ -39,7 +45,17 @@ public class CaptchaController extends com.anji.captcha.controller.CaptchaContro
@PermitAll @PermitAll
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志 @OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) { public ResponseModel check(@RequestBody CaptchaVO data, HttpServletRequest request) {
return super.check(data, request); data.setBrowserInfo(getRemoteId(request));
return captchaService.check(data);
}
public static String getRemoteId(HttpServletRequest request) {
String ip = ServletUtil.getClientIP(request);
String ua = request.getHeader("user-agent");
if (StrUtil.isNotBlank(ip)) {
return ip + ua;
}
return request.getRemoteAddr() + ua;
} }
} }