!324 系统配置读取方式变更
1、前端登录页面注册开关 对接后端数据库
2、密码最大错误次数与锁定时间转移到数据库
3、短信开关与验证码模板id 转移到数据库参数管理内
| | |
| | | |
| | | 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; |
| | |
| | | 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); |
| | | } |
| | |
| | | return R.ok(vo); |
| | | } |
| | | |
| | | /** |
| | | * 注册开关 |
| | | * |
| | | * @return ture:打开 false:关闭 |
| | | */ |
| | | @SaIgnore |
| | | @GetMapping("/registerEnabled") |
| | | public R<Boolean> registerEnabled() { |
| | | return R.ok(Convert.toBool(configService.selectConfigByKey("sys.account.registerUser"))); |
| | | } |
| | | |
| | | } |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | public class CaptchaController { |
| | | |
| | | private final CaptchaProperties captchaProperties; |
| | | private final SmsProperties smsProperties; |
| | | private final MailProperties mailProperties; |
| | | private final ISysConfigService configService; |
| | | |
| | | |
| | | /** |
| | | * 短信验证码 |
| | |
| | | */ |
| | | @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); |
| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | | * 登录验证 |
| | |
| | | |
| | | // 获取用户登录错误次数(可自定义限制策略 例如: 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)); |
| | |
| | | org.springframework: warn |
| | | config: classpath:logback.xml |
| | | |
| | | # 用户配置 |
| | | user: |
| | | password: |
| | | # 密码最大错误次数 |
| | | maxRetryCount: 5 |
| | | # 密码锁定时间(默认10分钟) |
| | | lockTime: 10 |
| | | |
| | | # Spring配置 |
| | | spring: |
| | | application: |
| | |
| | | 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; |
| | |
| | | public class SmsConfig { |
| | | |
| | | @Configuration |
| | | @ConditionalOnProperty(value = "sms.enabled", havingValue = "true") |
| | | @ConditionalOnClass(com.aliyun.dysmsapi20170525.Client.class) |
| | | static class AliyunSmsConfig { |
| | | |
| | |
| | | } |
| | | |
| | | @Configuration |
| | | @ConditionalOnProperty(value = "sms.enabled", havingValue = "true") |
| | | @ConditionalOnClass(com.tencentcloudapi.sms.v20190711.SmsClient.class) |
| | | static class TencentSmsConfig { |
| | | |
| | |
| | | @ConfigurationProperties(prefix = "sms") |
| | | public class SmsProperties { |
| | | |
| | | private Boolean enabled; |
| | | |
| | | /** |
| | | * 配置节点 |
| | | * 阿里云 dysmsapi.aliyuncs.com |
| | |
| | | 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; |
| | |
| | | @RequestMapping("/demo/sms") |
| | | public class SmsController { |
| | | |
| | | private final SmsProperties smsProperties; |
| | | private final ConfigService configService; |
| | | // private final SmsTemplate smsTemplate; // 可以使用spring注入 |
| | | // private final AliyunSmsTemplate smsTemplate; // 也可以注入某个厂家的模板工具 |
| | | |
| | |
| | | */ |
| | | @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")) { |
| | |
| | | */ |
| | | @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")) { |
| | |
| | | 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:关闭'); |
| | | |
| | | |
| | |
| | | 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:关闭'); |
| | | |
| | | |
| | |
| | | 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、系统访问记录 |
| | |
| | | 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 |
| | | |