!324 系统配置读取方式变更
1、前端登录页面注册开关 对接后端数据库 2、密码最大错误次数与锁定时间转移到数据库 3、短信开关与验证码模板id 转移到数据库参数管理内
This commit is contained in:
parent
210570c005
commit
5b39017708
@ -2,6 +2,7 @@ package com.ruoyi.web.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.domain.model.EmailLoginBody;
|
||||
import com.ruoyi.common.core.domain.model.LoginBody;
|
||||
@ -57,9 +58,9 @@ public class AuthController {
|
||||
LoginVo loginVo = new LoginVo();
|
||||
// 生成令牌
|
||||
String token = loginService.login(
|
||||
body.getTenantId(),
|
||||
body.getUsername(), body.getPassword(),
|
||||
body.getCode(), body.getUuid());
|
||||
body.getTenantId(),
|
||||
body.getUsername(), body.getPassword(),
|
||||
body.getCode(), body.getUuid());
|
||||
loginVo.setToken(token);
|
||||
return R.ok(loginVo);
|
||||
}
|
||||
@ -150,4 +151,15 @@ public class AuthController {
|
||||
return R.ok(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册开关
|
||||
*
|
||||
* @return ture:打开 false:关闭
|
||||
*/
|
||||
@SaIgnore
|
||||
@GetMapping("/registerEnabled")
|
||||
public R<Boolean> registerEnabled() {
|
||||
return R.ok(Convert.toBool(configService.selectConfigByKey("sys.account.registerUser")));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.ruoyi.web.controller;
|
||||
import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.hutool.captcha.AbstractCaptcha;
|
||||
import cn.hutool.captcha.generator.CodeGenerator;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
@ -14,11 +15,11 @@ import com.ruoyi.common.core.utils.reflect.ReflectUtils;
|
||||
import com.ruoyi.common.mail.config.properties.MailProperties;
|
||||
import com.ruoyi.common.mail.utils.MailUtils;
|
||||
import com.ruoyi.common.redis.utils.RedisUtils;
|
||||
import com.ruoyi.common.sms.config.properties.SmsProperties;
|
||||
import com.ruoyi.common.sms.core.SmsTemplate;
|
||||
import com.ruoyi.common.sms.entity.SmsResult;
|
||||
import com.ruoyi.common.web.config.properties.CaptchaProperties;
|
||||
import com.ruoyi.common.web.enums.CaptchaType;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.web.domain.vo.CaptchaVo;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -47,8 +48,9 @@ import java.util.Map;
|
||||
public class CaptchaController {
|
||||
|
||||
private final CaptchaProperties captchaProperties;
|
||||
private final SmsProperties smsProperties;
|
||||
private final MailProperties mailProperties;
|
||||
private final ISysConfigService configService;
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码
|
||||
@ -57,14 +59,14 @@ public class CaptchaController {
|
||||
*/
|
||||
@GetMapping("/sms/code")
|
||||
public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
|
||||
if (!smsProperties.getEnabled()) {
|
||||
if (!Convert.toBool(configService.selectConfigByKey("sys.account.smsEnabled"))) {
|
||||
return R.fail("当前系统没有开启短信功能!");
|
||||
}
|
||||
String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
|
||||
String code = RandomUtil.randomNumbers(4);
|
||||
RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
|
||||
// 验证码模板id 自行处理 (查数据库或写死均可)
|
||||
String templateId = "";
|
||||
String templateId = configService.selectConfigByKey("sys.account.templateId");
|
||||
Map<String, String> map = new HashMap<>(1);
|
||||
map.put("code", code);
|
||||
SmsTemplate smsTemplate = SpringUtils.getBean(SmsTemplate.class);
|
||||
|
@ -4,6 +4,7 @@ import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
@ -30,11 +31,11 @@ import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.vo.SysTenantVo;
|
||||
import com.ruoyi.system.domain.vo.SysUserVo;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysPermissionService;
|
||||
import com.ruoyi.system.service.ISysTenantService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Duration;
|
||||
@ -57,11 +58,7 @@ public class SysLoginService {
|
||||
private final ISysPermissionService permissionService;
|
||||
private final ISysTenantService tenantService;
|
||||
|
||||
@Value("${user.password.maxRetryCount}")
|
||||
private Integer maxRetryCount;
|
||||
|
||||
@Value("${user.password.lockTime}")
|
||||
private Integer lockTime;
|
||||
private final ISysConfigService configService;
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
@ -340,6 +337,10 @@ public class SysLoginService {
|
||||
|
||||
// 获取用户登录错误次数(可自定义限制策略 例如: key + username + ip)
|
||||
Integer errorNumber = RedisUtils.getCacheObject(errorKey);
|
||||
//密码最大错误次数
|
||||
Integer maxRetryCount = Convert.toInt(configService.selectConfigByKey("sys.user.maxRetryCount"));
|
||||
//密码锁定时间
|
||||
Integer lockTime = Convert.toInt(configService.selectConfigByKey("sys.user.lockTime"));
|
||||
// 锁定时间内登录 则踢出
|
||||
if (ObjectUtil.isNotNull(errorNumber) && errorNumber.equals(maxRetryCount)) {
|
||||
recordLogininfor(tenantId, username, loginFail, MessageUtils.message(loginType.getRetryLimitExceed(), maxRetryCount, lockTime));
|
||||
|
@ -52,14 +52,6 @@ logging:
|
||||
org.springframework: warn
|
||||
config: classpath:logback.xml
|
||||
|
||||
# 用户配置
|
||||
user:
|
||||
password:
|
||||
# 密码最大错误次数
|
||||
maxRetryCount: 5
|
||||
# 密码锁定时间(默认10分钟)
|
||||
lockTime: 10
|
||||
|
||||
# Spring配置
|
||||
spring:
|
||||
application:
|
||||
|
@ -6,7 +6,6 @@ import com.ruoyi.common.sms.core.SmsTemplate;
|
||||
import com.ruoyi.common.sms.core.TencentSmsTemplate;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -22,7 +21,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
public class SmsConfig {
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "sms.enabled", havingValue = "true")
|
||||
@ConditionalOnClass(com.aliyun.dysmsapi20170525.Client.class)
|
||||
static class AliyunSmsConfig {
|
||||
|
||||
@ -34,7 +32,6 @@ public class SmsConfig {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = "sms.enabled", havingValue = "true")
|
||||
@ConditionalOnClass(com.tencentcloudapi.sms.v20190711.SmsClient.class)
|
||||
static class TencentSmsConfig {
|
||||
|
||||
|
@ -13,8 +13,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@ConfigurationProperties(prefix = "sms")
|
||||
public class SmsProperties {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 配置节点
|
||||
* 阿里云 dysmsapi.aliyuncs.com
|
||||
|
@ -1,8 +1,9 @@
|
||||
package com.ruoyi.demo.controller;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.service.ConfigService;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.common.sms.config.properties.SmsProperties;
|
||||
import com.ruoyi.common.sms.core.SmsTemplate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -26,7 +27,7 @@ import java.util.Map;
|
||||
@RequestMapping("/demo/sms")
|
||||
public class SmsController {
|
||||
|
||||
private final SmsProperties smsProperties;
|
||||
private final ConfigService configService;
|
||||
// private final SmsTemplate smsTemplate; // 可以使用spring注入
|
||||
// private final AliyunSmsTemplate smsTemplate; // 也可以注入某个厂家的模板工具
|
||||
|
||||
@ -38,7 +39,7 @@ public class SmsController {
|
||||
*/
|
||||
@GetMapping("/sendAliyun")
|
||||
public R<Object> sendAliyun(String phones, String templateId) {
|
||||
if (!smsProperties.getEnabled()) {
|
||||
if (!Convert.toBool(configService.getConfigValue("sys.account.smsEnabled"))) {
|
||||
return R.fail("当前系统没有开启短信功能!");
|
||||
}
|
||||
if (!SpringUtils.containsBean("aliyunSmsTemplate")) {
|
||||
@ -59,7 +60,7 @@ public class SmsController {
|
||||
*/
|
||||
@GetMapping("/sendTencent")
|
||||
public R<Object> sendTencent(String phones, String templateId) {
|
||||
if (!smsProperties.getEnabled()) {
|
||||
if (!Convert.toBool(configService.getConfigValue("sys.account.smsEnabled"))) {
|
||||
return R.fail("当前系统没有开启短信功能!");
|
||||
}
|
||||
if (!SpringUtils.containsBean("tencentSmsTemplate")) {
|
||||
|
@ -828,6 +828,10 @@ insert into sys_config values(1, '000000', '主框架页-默认皮肤样式名
|
||||
insert into sys_config values(2, '000000', '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate, null, null, '初始化密码 123456' );
|
||||
insert into sys_config values(3, '000000', '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate, null, null, '深色主题theme-dark,浅色主题theme-light' );
|
||||
insert into sys_config values(5, '000000', '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate, null, null, '是否开启注册用户功能(true开启,false关闭)');
|
||||
insert into sys_config values(6, '000000', '用户配置-密码最大错误次数', 'sys.user.maxRetryCount', '5', 'Y', 103, 1, sysdate, null, null, '密码最大错误次数');
|
||||
insert into sys_config values(7, '000000', '用户配置-密码锁定时间', 'sys.user.lockTime', '10', 'Y', 103, 1, sysdate, null, null, '密码锁定时间(分钟)');
|
||||
insert into sys_config values(8, '000000', '账号自助-短信开关', 'sys.account.smsEnabled', 'false', 'Y', 103, 1, sysdate, null, null, '是否开启短信功能(true开启,false关闭)');
|
||||
insert into sys_config values(9, '000000', '账号自助-验证码模板id', 'sys.account.templateId', '', 'Y', 103, 1, sysdate, null, null, '验证码模板id');
|
||||
insert into sys_config values(11, '000000', 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate, null, null, 'true:开启, false:关闭');
|
||||
|
||||
|
||||
|
@ -849,6 +849,10 @@ insert into sys_config values(1, '000000', '主框架页-默认皮肤样式名
|
||||
insert into sys_config values(2, '000000', '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, now(), null, null, '初始化密码 123456' );
|
||||
insert into sys_config values(3, '000000', '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, now(), null, null, '深色主题theme-dark,浅色主题theme-light' );
|
||||
insert into sys_config values(5, '000000', '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, now(), null, null, '是否开启注册用户功能(true开启,false关闭)');
|
||||
insert into sys_config values(6, '000000', '用户配置-密码最大错误次数', 'sys.user.maxRetryCount', '5', 'Y', 103, 1,now(), null, null, '密码最大错误次数');
|
||||
insert into sys_config values(7, '000000', '用户配置-密码锁定时间', 'sys.user.lockTime', '10', 'Y', 103, 1, now(), null, null, '密码锁定时间(分钟)');
|
||||
insert into sys_config values(8, '000000', '账号自助-短信开关', 'sys.account.smsEnabled', 'false', 'Y', 103, 1, now(), null, null, '是否开启短信功能(true开启,false关闭)');
|
||||
insert into sys_config values(9, '000000', '账号自助-验证码模板id', 'sys.account.templateId', '', 'Y', 103, 1, now(), null, null, '验证码模板id');
|
||||
insert into sys_config values(11, '000000', 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, now(), null, null, 'true:开启, false:关闭');
|
||||
|
||||
|
||||
|
@ -625,12 +625,16 @@ create table sys_config (
|
||||
primary key (config_id)
|
||||
) engine=innodb comment = '参数配置表';
|
||||
|
||||
insert into sys_config values(1, '000000', '主框架页-默认皮肤样式名称', '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, '000000', '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate(), null, null, '初始化密码 123456' );
|
||||
insert into sys_config values(3, '000000', '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate(), null, null, '深色主题theme-dark,浅色主题theme-light' );
|
||||
insert into sys_config values(5, '000000', '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate(), null, null, '是否开启注册用户功能(true开启,false关闭)');
|
||||
insert into sys_config values(11, '000000', 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate(), null, null, 'true:开启, false:关闭');
|
||||
|
||||
insert into sys_config values(1, '000000', '主框架页-默认皮肤样式名称', '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, '000000', '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 103, 1, sysdate(), null, NULL, '初始化密码 123456');
|
||||
insert into sys_config values(3, '000000', '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 103, 1, sysdate(), null, NULL, '深色主题theme-dark,浅色主题theme-light');
|
||||
insert into sys_config values(4, '000000', '账号自助-验证码开关', 'sys.account.captchaEnabled', 'true', 'Y', 103, 1, sysdate(), null, NULL, '是否开启验证码功能(true开启,false关闭)');
|
||||
insert into sys_config values(5, '000000', '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'true', 'Y', 103, 1, sysdate(), null, NULL, '是否开启注册用户功能(true开启,false关闭)');
|
||||
insert into sys_config values(6, '000000', '用户配置-密码最大错误次数', 'sys.user.maxRetryCount', '5', 'Y', 103, 1, sysdate(), null, NULL, '密码最大错误次数');
|
||||
insert into sys_config values(7, '000000', '用户配置-密码锁定时间', 'sys.user.lockTime', '10', 'Y', 103, 1, sysdate(), null, NULL, '密码锁定时间(分钟)');
|
||||
insert into sys_config values(8, '000000', '账号自助-短信开关', 'sys.account.smsEnabled', 'false', 'Y', 103, 1, sysdate(), null, NULL, '是否开启短信功能(true开启,false关闭)');
|
||||
insert into sys_config values(9, '000000', '账号自助-验证码模板id', 'sys.account.templateId', '', 'Y', 103, 1, sysdate(), null, NULL, '验证码模板id');
|
||||
insert into sys_config values(11,'000000', 'OSS预览列表资源开关', 'sys.oss.previewListResource', 'true', 'Y', 103, 1, sysdate(), null, NULL, 'true:开启, false:关闭');
|
||||
|
||||
-- ----------------------------
|
||||
-- 14、系统访问记录
|
||||
|
@ -696,6 +696,14 @@ INSERT sys_config VALUES (3, N'000000', N'主框架页-侧边栏主题', N'sys.i
|
||||
GO
|
||||
INSERT sys_config VALUES (5, N'000000', N'账号自助-是否开启用户注册功能', N'sys.account.registerUser', N'false', N'Y', 103, 1, getdate(), NULL, NULL, N'是否开启注册用户功能(true开启,false关闭)')
|
||||
GO
|
||||
INSERT sys_config VALUES (6, N'000000', N'用户配置-密码最大错误次数', N'sys.user.maxRetryCount', N'5', N'Y', 103, 1, getdate(), NULL, NULL, N'密码最大错误次数')
|
||||
GO
|
||||
INSERT sys_config VALUES (7, N'000000', N'用户配置-密码锁定时间', N'sys.user.lockTime', N'10', N'Y', 103, 1, getdate(), NULL, NULL, N'密码锁定时间(分钟)')
|
||||
GO
|
||||
INSERT sys_config VALUES (8, N'000000', N'账号自助-短信开关', N'sys.account.smsEnabled', N'false', N'Y', 103, 1, getdate(), NULL, NULL, N'是否开启短信功能(true开启,false关闭)')
|
||||
GO
|
||||
INSERT sys_config VALUES (9, N'000000', N'账号自助-验证码模板id', N'sys.account.templateId', N'', N'Y', 103, 1, getdate(), NULL, NULL, N'验证码模板id')
|
||||
GO
|
||||
INSERT sys_config VALUES (11, N'000000', N'OSS预览列表资源开关', N'sys.oss.previewListResource', N'true', N'Y', 103, 1, getdate(), NULL, NULL, N'true:开启, false:关闭');
|
||||
GO
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user