新增登录验证码开关

This commit is contained in:
阿沐 2022-11-18 13:09:57 +08:00
parent d2fab3b212
commit cc316d5843
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,13 @@
package net.maku.system.enums;
/**
* 系统参数 枚举
*
* @author 阿沐 babamu@126.com
*/
public enum SysParamsEnum {
/**
* 登录验证码
*/
LOGIN_CAPTCHA
}

View File

@ -7,7 +7,9 @@ import com.wf.captcha.base.Captcha;
import lombok.AllArgsConstructor;
import net.maku.framework.common.cache.RedisCache;
import net.maku.framework.common.cache.RedisKeys;
import net.maku.system.enums.SysParamsEnum;
import net.maku.system.service.SysCaptchaService;
import net.maku.system.service.SysParamsService;
import net.maku.system.vo.SysCaptchaVO;
import org.springframework.stereotype.Service;
@ -20,6 +22,7 @@ import org.springframework.stereotype.Service;
@AllArgsConstructor
public class SysCaptchaServiceImpl implements SysCaptchaService {
private final RedisCache redisCache;
private final SysParamsService sysParamsService;
@Override
public SysCaptchaVO generate() {
@ -46,6 +49,11 @@ public class SysCaptchaServiceImpl implements SysCaptchaService {
@Override
public boolean validate(String key, String code) {
// 如果关闭了验证码则直接效验通过
if (!isCaptchaEnabled()) {
return true;
}
if (StrUtil.isBlank(key) || StrUtil.isBlank(code)) {
return false;
}
@ -67,4 +75,13 @@ public class SysCaptchaServiceImpl implements SysCaptchaService {
return captcha;
}
/**
* 是否开启登录验证码
*
* @return true开启 false关闭
*/
private boolean isCaptchaEnabled() {
return sysParamsService.getBoolean(SysParamsEnum.LOGIN_CAPTCHA.name());
}
}