mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 18:15:56 +08:00
update 重构 验证码开关使用配置文件(经调查少有动态开启需求)
This commit is contained in:
parent
0e172d2aa1
commit
edd93d1d38
@ -17,8 +17,8 @@ import com.ruoyi.common.sms.core.SmsTemplate;
|
|||||||
import com.ruoyi.common.sms.entity.SmsResult;
|
import com.ruoyi.common.sms.entity.SmsResult;
|
||||||
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||||
import com.ruoyi.common.web.enums.CaptchaType;
|
import com.ruoyi.common.web.enums.CaptchaType;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
|
||||||
import com.ruoyi.web.domain.vo.CaptchaVo;
|
import com.ruoyi.web.domain.vo.CaptchaVo;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
@ -28,7 +28,6 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -47,7 +46,6 @@ public class CaptchaController {
|
|||||||
|
|
||||||
private final CaptchaProperties captchaProperties;
|
private final CaptchaProperties captchaProperties;
|
||||||
private final SmsProperties smsProperties;
|
private final SmsProperties smsProperties;
|
||||||
private final ISysConfigService configService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信验证码
|
* 短信验证码
|
||||||
@ -82,7 +80,7 @@ public class CaptchaController {
|
|||||||
@GetMapping("/captchaImage")
|
@GetMapping("/captchaImage")
|
||||||
public R<CaptchaVo> getCode() {
|
public R<CaptchaVo> getCode() {
|
||||||
CaptchaVo captchaVo = new CaptchaVo();
|
CaptchaVo captchaVo = new CaptchaVo();
|
||||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
boolean captchaEnabled = captchaProperties.getEnable();
|
||||||
if (!captchaEnabled) {
|
if (!captchaEnabled) {
|
||||||
captchaVo.setCaptchaEnabled(false);
|
captchaVo.setCaptchaEnabled(false);
|
||||||
return R.ok(captchaVo);
|
return R.ok(captchaVo);
|
||||||
|
|||||||
@ -24,11 +24,11 @@ import com.ruoyi.common.log.event.LogininforEvent;
|
|||||||
import com.ruoyi.common.mybatis.helper.TenantHelper;
|
import com.ruoyi.common.mybatis.helper.TenantHelper;
|
||||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||||
import com.ruoyi.common.satoken.utils.LoginHelper;
|
import com.ruoyi.common.satoken.utils.LoginHelper;
|
||||||
|
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||||
import com.ruoyi.system.domain.SysUser;
|
import com.ruoyi.system.domain.SysUser;
|
||||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||||
import com.ruoyi.system.mapper.SysUserMapper;
|
import com.ruoyi.system.mapper.SysUserMapper;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
|
||||||
import com.ruoyi.system.service.ISysPermissionService;
|
import com.ruoyi.system.service.ISysPermissionService;
|
||||||
import com.ruoyi.system.service.ISysTenantService;
|
import com.ruoyi.system.service.ISysTenantService;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
@ -53,7 +53,7 @@ import java.util.function.Supplier;
|
|||||||
public class SysLoginService {
|
public class SysLoginService {
|
||||||
|
|
||||||
private final SysUserMapper userMapper;
|
private final SysUserMapper userMapper;
|
||||||
private final ISysConfigService configService;
|
private final CaptchaProperties captchaProperties;
|
||||||
private final ISysPermissionService permissionService;
|
private final ISysPermissionService permissionService;
|
||||||
private final ISysTenantService tenantService;
|
private final ISysTenantService tenantService;
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ public class SysLoginService {
|
|||||||
*/
|
*/
|
||||||
public String login(String tenantId, String username, String password, String code, String uuid) {
|
public String login(String tenantId, String username, String password, String code, String uuid) {
|
||||||
HttpServletRequest request = ServletUtils.getRequest();
|
HttpServletRequest request = ServletUtils.getRequest();
|
||||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
boolean captchaEnabled = captchaProperties.getEnable();
|
||||||
// 验证码开关
|
// 验证码开关
|
||||||
if (captchaEnabled) {
|
if (captchaEnabled) {
|
||||||
validateCaptcha(tenantId, username, code, uuid, request);
|
validateCaptcha(tenantId, username, code, uuid, request);
|
||||||
|
|||||||
@ -15,8 +15,8 @@ import com.ruoyi.common.core.utils.SpringUtils;
|
|||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.log.event.LogininforEvent;
|
import com.ruoyi.common.log.event.LogininforEvent;
|
||||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||||
|
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||||
import com.ruoyi.system.service.ISysConfigService;
|
|
||||||
import com.ruoyi.system.service.ISysUserService;
|
import com.ruoyi.system.service.ISysUserService;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -32,7 +32,7 @@ import org.springframework.stereotype.Service;
|
|||||||
public class SysRegisterService {
|
public class SysRegisterService {
|
||||||
|
|
||||||
private final ISysUserService userService;
|
private final ISysUserService userService;
|
||||||
private final ISysConfigService configService;
|
private final CaptchaProperties captchaProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册
|
* 注册
|
||||||
@ -45,7 +45,7 @@ public class SysRegisterService {
|
|||||||
// 校验用户类型是否存在
|
// 校验用户类型是否存在
|
||||||
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
|
String userType = UserType.getUserType(registerBody.getUserType()).getUserType();
|
||||||
|
|
||||||
boolean captchaEnabled = configService.selectCaptchaEnabled();
|
boolean captchaEnabled = captchaProperties.getEnable();
|
||||||
// 验证码开关
|
// 验证码开关
|
||||||
if (captchaEnabled) {
|
if (captchaEnabled) {
|
||||||
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid(), request);
|
validateCaptcha(tenantId, username, registerBody.getCode(), registerBody.getUuid(), request);
|
||||||
|
|||||||
@ -14,6 +14,7 @@ ruoyi:
|
|||||||
cacheLazy: false
|
cacheLazy: false
|
||||||
|
|
||||||
captcha:
|
captcha:
|
||||||
|
enable: true
|
||||||
# 页面 <参数设置> 可开启关闭 验证码校验
|
# 页面 <参数设置> 可开启关闭 验证码校验
|
||||||
# 验证码类型 math 数组计算 char 字符验证
|
# 验证码类型 math 数组计算 char 字符验证
|
||||||
type: MATH
|
type: MATH
|
||||||
|
|||||||
@ -14,6 +14,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
@ConfigurationProperties(prefix = "captcha")
|
@ConfigurationProperties(prefix = "captcha")
|
||||||
public class CaptchaProperties {
|
public class CaptchaProperties {
|
||||||
|
|
||||||
|
private Boolean enable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码类型
|
* 验证码类型
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -820,7 +820,6 @@ comment on column sys_config.remark is '备注';
|
|||||||
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 103, 1, sysdate, null, null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 103, 1, sysdate, null, null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
||||||
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate, null, null, '初始化密码 123456' );
|
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate, null, null, '初始化密码 123456' );
|
||||||
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate, null, null, '深色主题theme-dark,浅色主题theme-light' );
|
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate, null, null, '深色主题theme-dark,浅色主题theme-light' );
|
||||||
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaEnabled', 'true', 'Y', 103, 1, sysdate, null, null, '是否开启验证码功能(true开启,false关闭)');
|
|
||||||
insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate, null, null, '是否开启注册用户功能(true开启,false关闭)');
|
insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate, null, null, '是否开启注册用户功能(true开启,false关闭)');
|
||||||
insert into sys_config values(11, 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate, null, null, 'true:开启, false:关闭');
|
insert into sys_config values(11, 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate, null, null, 'true:开启, false:关闭');
|
||||||
|
|
||||||
|
|||||||
@ -839,7 +839,6 @@ comment on column sys_config.remark is '备注';
|
|||||||
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 103, 1, now(), null, null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 103, 1, now(), null, null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
||||||
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, now(), null, null, '初始化密码 123456' );
|
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, now(), null, null, '初始化密码 123456' );
|
||||||
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, now(), null, null, '深色主题theme-dark,浅色主题theme-light' );
|
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, now(), null, null, '深色主题theme-dark,浅色主题theme-light' );
|
||||||
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaEnabled', 'true', 'Y', 103, 1, now(), null, null, '是否开启验证码功能(true开启,false关闭)');
|
|
||||||
insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, now(), null, null, '是否开启注册用户功能(true开启,false关闭)');
|
insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, now(), null, null, '是否开启注册用户功能(true开启,false关闭)');
|
||||||
insert into sys_config values(11, 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, now(), null, null, 'true:开启, false:关闭');
|
insert into sys_config values(11, 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, now(), null, null, 'true:开启, false:关闭');
|
||||||
|
|
||||||
|
|||||||
@ -623,7 +623,6 @@ create table sys_config (
|
|||||||
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 103, 1, sysdate(), null, null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 103, 1, sysdate(), null, null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow' );
|
||||||
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate(), null, null, '初始化密码 123456' );
|
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate(), null, null, '初始化密码 123456' );
|
||||||
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate(), null, null, '深色主题theme-dark,浅色主题theme-light' );
|
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate(), null, null, '深色主题theme-dark,浅色主题theme-light' );
|
||||||
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaEnabled', 'true', 'Y', 103, 1, sysdate(), null, null, '是否开启验证码功能(true开启,false关闭)');
|
|
||||||
insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate(), null, null, '是否开启注册用户功能(true开启,false关闭)');
|
insert into sys_config values(5, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate(), null, null, '是否开启注册用户功能(true开启,false关闭)');
|
||||||
insert into sys_config values(11, 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate(), null, null, 'true:开启, false:关闭');
|
insert into sys_config values(11, 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate(), null, null, 'true:开启, false:关闭');
|
||||||
|
|
||||||
|
|||||||
@ -680,8 +680,6 @@ INSERT sys_config VALUES (2, N'用户管理-账号初始密码', N'sys.user.init
|
|||||||
GO
|
GO
|
||||||
INSERT sys_config VALUES (3, N'主框架页-侧边栏主题', N'sys.index.sideTheme', N'theme-dark', N'Y', 103, 1, getdate(), NULL, NULL, N'深色主题theme-dark,浅色主题theme-light')
|
INSERT sys_config VALUES (3, N'主框架页-侧边栏主题', N'sys.index.sideTheme', N'theme-dark', N'Y', 103, 1, getdate(), NULL, NULL, N'深色主题theme-dark,浅色主题theme-light')
|
||||||
GO
|
GO
|
||||||
INSERT sys_config VALUES (4, N'账号自助-验证码开关', N'sys.account.captchaEnabled', N'true', N'Y', 103, 1, getdate(), NULL, NULL, N'是否开启验证码功能(true开启,false关闭)')
|
|
||||||
GO
|
|
||||||
INSERT sys_config VALUES (5, N'账号自助-是否开启用户注册功能', N'sys.account.registerUser', N'false', N'Y', 103, 1, getdate(), NULL, NULL, N'是否开启注册用户功能(true开启,false关闭)')
|
INSERT sys_config VALUES (5, N'账号自助-是否开启用户注册功能', N'sys.account.registerUser', N'false', N'Y', 103, 1, getdate(), NULL, NULL, N'是否开启注册用户功能(true开启,false关闭)')
|
||||||
GO
|
GO
|
||||||
INSERT sys_config VALUES (11, N'OSS预览列表资源开关', N'sys.oss.previewListResource', N'true', N'Y', 103, 1, getdate(), NULL, NULL, N'true:开启, false:关闭');
|
INSERT sys_config VALUES (11, N'OSS预览列表资源开关', N'sys.oss.previewListResource', N'true', N'Y', 103, 1, getdate(), NULL, NULL, N'true:开启, false:关闭');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user