From 0d218cd7ba73f97f6173e56118919cfd63d1f4df Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Sat, 27 Jul 2024 23:36:23 +0800 Subject: [PATCH] =?UTF-8?q?=20feat(=E6=96=B0=E5=A2=9E):=20:rocket:=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=9B=BE=E7=89=87=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/config/WebMvcConfiguration.java | 5 ++- .../security/config/WebSecurityConfig.java | 5 +-- .../service/controller/WebController.java | 31 +++++++++++++++++++ .../bunny/service/service/LoginService.java | 10 ++++++ .../service/impl/LoginServiceImpl.java | 21 +++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 service/src/main/java/cn/bunny/service/controller/WebController.java create mode 100644 service/src/main/java/cn/bunny/service/service/LoginService.java create mode 100644 service/src/main/java/cn/bunny/service/service/impl/LoginServiceImpl.java diff --git a/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java b/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java index 34dd3b5..abfaafc 100644 --- a/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java +++ b/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java @@ -30,8 +30,11 @@ public class WebMvcConfiguration implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - String[] excludeList = {"/api/checkCode", "/api/sendEmailCode", "/api/register", "/api/login", "/api/article/loadArticle/**"}; log.info("WebMvcConfiguration===>开始注册自定义拦截器..."); + + String[] excludeList = {"/api/checkCode", "/api/sendEmailCode", "/api/register", "/api/login",}; + registry.addInterceptor(userTokenInterceptor).excludePathPatterns(excludeList); + // TODO 如果想使用普通JWT可以使用这个,不使用 SpringSecurity6 // registry.addInterceptor(userTokenInterceptor).addPathPatterns("/api/**").excludePathPatterns(excludeList); } diff --git a/module/spring-security/src/main/java/cn/bunny/security/config/WebSecurityConfig.java b/module/spring-security/src/main/java/cn/bunny/security/config/WebSecurityConfig.java index 5899405..1dfde60 100644 --- a/module/spring-security/src/main/java/cn/bunny/security/config/WebSecurityConfig.java +++ b/module/spring-security/src/main/java/cn/bunny/security/config/WebSecurityConfig.java @@ -88,8 +88,9 @@ public class WebSecurityConfig { // 排出鉴定路径 @Bean public WebSecurityCustomizer webSecurityCustomizer() { - String[] annotations = {"/", "/test/**", "/diagram-viewer/**", "/editor-app/**", "/*.html", - "/*/*/noAuth/**", "/*/noAuth/**", "/favicon.ico", "/swagger-resources/**", "/webjars/**", "/v3/**", "/swagger-ui.html/**", "/doc.html"}; + String[] annotations = {"/", "/test/**", "/*.html", "/*/*/noAuth/**", "/*/noAuth/**", "/favicon.ico", "/swagger-resources/**", "/swagger-ui.html/**", + "/api/**" + }; return web -> web.ignoring().requestMatchers(annotations); } } diff --git a/service/src/main/java/cn/bunny/service/controller/WebController.java b/service/src/main/java/cn/bunny/service/controller/WebController.java new file mode 100644 index 0000000..88e4fb6 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/controller/WebController.java @@ -0,0 +1,31 @@ +package cn.bunny.service.controller; + +import cn.bunny.service.service.LoginService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "web相关接口") +@RestController +@RequestMapping("/api") +public class WebController { + @Autowired + private LoginService loginService; + + @Operation(summary = "生成验证码", description = "生成验证码") + @GetMapping("checkCode") + public ResponseEntity checkCode() { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.IMAGE_JPEG); + + byte[] image = loginService.checkCode(); + return new ResponseEntity(image, headers, HttpStatus.OK); + } +} diff --git a/service/src/main/java/cn/bunny/service/service/LoginService.java b/service/src/main/java/cn/bunny/service/service/LoginService.java new file mode 100644 index 0000000..6a2dd06 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/service/LoginService.java @@ -0,0 +1,10 @@ +package cn.bunny.service.service; + +public interface LoginService { + /** + * * 生成验证码 + * + * @return 验证码图片数组 + */ + byte[] checkCode(); +} diff --git a/service/src/main/java/cn/bunny/service/service/impl/LoginServiceImpl.java b/service/src/main/java/cn/bunny/service/service/impl/LoginServiceImpl.java new file mode 100644 index 0000000..36023b1 --- /dev/null +++ b/service/src/main/java/cn/bunny/service/service/impl/LoginServiceImpl.java @@ -0,0 +1,21 @@ +package cn.bunny.service.service.impl; + +import cn.bunny.service.service.LoginService; +import cn.hutool.captcha.CaptchaUtil; +import cn.hutool.captcha.CircleCaptcha; +import org.springframework.stereotype.Service; + +@Service +public class LoginServiceImpl implements LoginService { + /** + * * 生成验证码 + * + * @return 验证码图片数组 + */ + @Override + public byte[] checkCode() { + // 生成验证码 + CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(150, 48, 4, 2); + return captcha.getImageBytes(); + } +}