From af0c4ed21481d06c95dd84f18970a031c7869bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E6=B2=90?= Date: Fri, 16 Jun 2023 11:31:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/maku/system/controller/SysAuthController.java | 8 ++++++++ .../net/maku/system/service/SysCaptchaService.java | 7 +++++++ .../system/service/impl/SysCaptchaServiceImpl.java | 19 +++++-------------- .../main/java/net/maku/system/vo/SysCaptchaVO.java | 3 --- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/maku-boot-system/src/main/java/net/maku/system/controller/SysAuthController.java b/maku-boot-system/src/main/java/net/maku/system/controller/SysAuthController.java index 113b212..e340f6c 100644 --- a/maku-boot-system/src/main/java/net/maku/system/controller/SysAuthController.java +++ b/maku-boot-system/src/main/java/net/maku/system/controller/SysAuthController.java @@ -36,6 +36,14 @@ public class SysAuthController { return Result.ok(captchaVO); } + @GetMapping("captcha/enabled") + @Operation(summary = "是否开启验证码") + public Result captchaEnabled() { + boolean enabled = sysCaptchaService.isCaptchaEnabled(); + + return Result.ok(enabled); + } + @PostMapping("login") @Operation(summary = "账号密码登录") public Result login(@RequestBody SysAccountLoginVO login) { diff --git a/maku-boot-system/src/main/java/net/maku/system/service/SysCaptchaService.java b/maku-boot-system/src/main/java/net/maku/system/service/SysCaptchaService.java index 8853f00..568acf3 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/SysCaptchaService.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/SysCaptchaService.java @@ -22,4 +22,11 @@ public interface SysCaptchaService { * @return true:成功 false:失败 */ boolean validate(String key, String code); + + /** + * 是否开启登录验证码 + * + * @return true:开启 false:关闭 + */ + boolean isCaptchaEnabled(); } diff --git a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysCaptchaServiceImpl.java b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysCaptchaServiceImpl.java index 395642b..a3d6e91 100644 --- a/maku-boot-system/src/main/java/net/maku/system/service/impl/SysCaptchaServiceImpl.java +++ b/maku-boot-system/src/main/java/net/maku/system/service/impl/SysCaptchaServiceImpl.java @@ -27,11 +27,6 @@ public class SysCaptchaServiceImpl implements SysCaptchaService { @Override public SysCaptchaVO generate() { - // 判断是否开启验证码 - if (!isCaptchaEnabled()) { - return new SysCaptchaVO(); - } - // 生成验证码key String key = UUID.randomUUID().toString(); @@ -49,7 +44,6 @@ public class SysCaptchaServiceImpl implements SysCaptchaService { SysCaptchaVO captchaVO = new SysCaptchaVO(); captchaVO.setKey(key); captchaVO.setImage(image); - captchaVO.setEnabled(true); return captchaVO; } @@ -72,6 +66,11 @@ public class SysCaptchaServiceImpl implements SysCaptchaService { return code.equalsIgnoreCase(captcha); } + @Override + public boolean isCaptchaEnabled() { + return sysParamsService.getBoolean(SysParamsEnum.LOGIN_CAPTCHA.name()); + } + private String getCache(String key) { key = RedisKeys.getCaptchaKey(key); String captcha = (String) redisCache.get(key); @@ -83,12 +82,4 @@ public class SysCaptchaServiceImpl implements SysCaptchaService { return captcha; } - /** - * 是否开启登录验证码 - * - * @return true:开启 false:关闭 - */ - private boolean isCaptchaEnabled() { - return sysParamsService.getBoolean(SysParamsEnum.LOGIN_CAPTCHA.name()); - } } diff --git a/maku-boot-system/src/main/java/net/maku/system/vo/SysCaptchaVO.java b/maku-boot-system/src/main/java/net/maku/system/vo/SysCaptchaVO.java index fede657..3143aff 100644 --- a/maku-boot-system/src/main/java/net/maku/system/vo/SysCaptchaVO.java +++ b/maku-boot-system/src/main/java/net/maku/system/vo/SysCaptchaVO.java @@ -21,7 +21,4 @@ public class SysCaptchaVO implements Serializable { @Schema(description = "image base64") private String image; - - @Schema(description = "是否开启验证码") - private boolean enabled; }