获取验证码逻辑
This commit is contained in:
parent
407c4217cf
commit
af0c4ed214
|
@ -36,6 +36,14 @@ public class SysAuthController {
|
|||
return Result.ok(captchaVO);
|
||||
}
|
||||
|
||||
@GetMapping("captcha/enabled")
|
||||
@Operation(summary = "是否开启验证码")
|
||||
public Result<Boolean> captchaEnabled() {
|
||||
boolean enabled = sysCaptchaService.isCaptchaEnabled();
|
||||
|
||||
return Result.ok(enabled);
|
||||
}
|
||||
|
||||
@PostMapping("login")
|
||||
@Operation(summary = "账号密码登录")
|
||||
public Result<SysTokenVO> login(@RequestBody SysAccountLoginVO login) {
|
||||
|
|
|
@ -22,4 +22,11 @@ public interface SysCaptchaService {
|
|||
* @return true:成功 false:失败
|
||||
*/
|
||||
boolean validate(String key, String code);
|
||||
|
||||
/**
|
||||
* 是否开启登录验证码
|
||||
*
|
||||
* @return true:开启 false:关闭
|
||||
*/
|
||||
boolean isCaptchaEnabled();
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,4 @@ public class SysCaptchaVO implements Serializable {
|
|||
|
||||
@Schema(description = "image base64")
|
||||
private String image;
|
||||
|
||||
@Schema(description = "是否开启验证码")
|
||||
private boolean enabled;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user