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; }