获取验证码逻辑

This commit is contained in:
阿沐 2023-06-16 11:31:05 +08:00
parent 407c4217cf
commit af0c4ed214
4 changed files with 20 additions and 17 deletions

View File

@ -36,6 +36,14 @@ public class SysAuthController {
return Result.ok(captchaVO); return Result.ok(captchaVO);
} }
@GetMapping("captcha/enabled")
@Operation(summary = "是否开启验证码")
public Result<Boolean> captchaEnabled() {
boolean enabled = sysCaptchaService.isCaptchaEnabled();
return Result.ok(enabled);
}
@PostMapping("login") @PostMapping("login")
@Operation(summary = "账号密码登录") @Operation(summary = "账号密码登录")
public Result<SysTokenVO> login(@RequestBody SysAccountLoginVO login) { public Result<SysTokenVO> login(@RequestBody SysAccountLoginVO login) {

View File

@ -22,4 +22,11 @@ public interface SysCaptchaService {
* @return true成功 false失败 * @return true成功 false失败
*/ */
boolean validate(String key, String code); boolean validate(String key, String code);
/**
* 是否开启登录验证码
*
* @return true开启 false关闭
*/
boolean isCaptchaEnabled();
} }

View File

@ -27,11 +27,6 @@ public class SysCaptchaServiceImpl implements SysCaptchaService {
@Override @Override
public SysCaptchaVO generate() { public SysCaptchaVO generate() {
// 判断是否开启验证码
if (!isCaptchaEnabled()) {
return new SysCaptchaVO();
}
// 生成验证码key // 生成验证码key
String key = UUID.randomUUID().toString(); String key = UUID.randomUUID().toString();
@ -49,7 +44,6 @@ public class SysCaptchaServiceImpl implements SysCaptchaService {
SysCaptchaVO captchaVO = new SysCaptchaVO(); SysCaptchaVO captchaVO = new SysCaptchaVO();
captchaVO.setKey(key); captchaVO.setKey(key);
captchaVO.setImage(image); captchaVO.setImage(image);
captchaVO.setEnabled(true);
return captchaVO; return captchaVO;
} }
@ -72,6 +66,11 @@ public class SysCaptchaServiceImpl implements SysCaptchaService {
return code.equalsIgnoreCase(captcha); return code.equalsIgnoreCase(captcha);
} }
@Override
public boolean isCaptchaEnabled() {
return sysParamsService.getBoolean(SysParamsEnum.LOGIN_CAPTCHA.name());
}
private String getCache(String key) { private String getCache(String key) {
key = RedisKeys.getCaptchaKey(key); key = RedisKeys.getCaptchaKey(key);
String captcha = (String) redisCache.get(key); String captcha = (String) redisCache.get(key);
@ -83,12 +82,4 @@ public class SysCaptchaServiceImpl implements SysCaptchaService {
return captcha; return captcha;
} }
/**
* 是否开启登录验证码
*
* @return true开启 false关闭
*/
private boolean isCaptchaEnabled() {
return sysParamsService.getBoolean(SysParamsEnum.LOGIN_CAPTCHA.name());
}
} }

View File

@ -21,7 +21,4 @@ public class SysCaptchaVO implements Serializable {
@Schema(description = "image base64") @Schema(description = "image base64")
private String image; private String image;
@Schema(description = "是否开启验证码")
private boolean enabled;
} }