Browse Source

reset !pr324 有逻辑性问题 暂时回滚

疯狂的狮子Li 2 years ago
parent
commit
92e15c2f16

+ 3 - 14
ruoyi-admin/src/main/java/com/ruoyi/web/controller/AuthController.java

@@ -2,7 +2,6 @@ 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;
@@ -58,9 +57,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);
     }
@@ -151,14 +150,4 @@ public class AuthController {
         return R.ok(vo);
     }
 
-    /**
-     * 注册开关
-     *
-     * @return ture:打开 false:关闭
-     */
-    @GetMapping("/registerEnabled")
-    public R<Boolean> registerEnabled() {
-        return R.ok(Convert.toBool(configService.selectConfigByKey("sys.account.registerUser")));
-    }
-
 }

+ 9 - 13
ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java

@@ -3,9 +3,9 @@ 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;
 import com.ruoyi.common.core.constant.GlobalConstants;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.SpringUtils;
@@ -14,11 +14,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,9 +47,8 @@ import java.util.Map;
 public class CaptchaController {
 
     private final CaptchaProperties captchaProperties;
+    private final SmsProperties smsProperties;
     private final MailProperties mailProperties;
-    private final ISysConfigService configService;
-
 
     /**
      * 短信验证码
@@ -58,15 +57,14 @@ public class CaptchaController {
      */
     @GetMapping("/sms/code")
     public R<Void> smsCode(@NotBlank(message = "{user.phonenumber.not.blank}") String phonenumber) {
-        if (!Convert.toBool(configService.selectConfigByKey("sys.account.smsEnabled"))) {
+        if (!smsProperties.getEnabled()) {
             return R.fail("当前系统没有开启短信功能!");
         }
         String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
         String code = RandomUtil.randomNumbers(4);
-        Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired"));
-        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(captchaExpired));
+        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
         // 验证码模板id 自行处理 (查数据库或写死均可)
-        String templateId = configService.selectConfigByKey("sys.account.templateId");
+        String templateId = "";
         Map<String, String> map = new HashMap<>(1);
         map.put("code", code);
         SmsTemplate smsTemplate = SpringUtils.getBean(SmsTemplate.class);
@@ -90,10 +88,9 @@ public class CaptchaController {
         }
         String key = GlobalConstants.CAPTCHA_CODE_KEY + email;
         String code = RandomUtil.randomNumbers(4);
-        Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired"));
-        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(captchaExpired));
+        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
         try {
-            MailUtils.sendText(email, "登录验证码", "您本次验证码为:%s,有效性为%d分钟,请尽快填写。".formatted(code, captchaExpired));
+            MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。");
         } catch (Exception e) {
             log.error("验证码短信发送异常 => {}", e.getMessage());
             return R.fail(e.getMessage());
@@ -129,8 +126,7 @@ public class CaptchaController {
             Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
             code = exp.getValue(String.class);
         }
-        Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired"));
-        RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(captchaExpired));
+        RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
         captchaVo.setUuid(uuid);
         captchaVo.setImg(captcha.getImageBase64());
         return R.ok(captchaVo);

+ 7 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/service/SysLoginService.java

@@ -4,7 +4,6 @@ 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;
@@ -31,11 +30,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,7 +56,12 @@ public class SysLoginService {
     private final CaptchaProperties captchaProperties;
     private final ISysPermissionService permissionService;
     private final ISysTenantService tenantService;
-    private final ISysConfigService configService;
+
+    @Value("${user.password.maxRetryCount}")
+    private Integer maxRetryCount;
+
+    @Value("${user.password.lockTime}")
+    private Integer lockTime;
 
     /**
      * 登录验证
@@ -336,10 +340,6 @@ 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));

+ 8 - 0
ruoyi-admin/src/main/resources/application.yml

@@ -52,6 +52,14 @@ logging:
     org.springframework: warn
   config: classpath:logback.xml
 
+# 用户配置
+user:
+  password:
+    # 密码最大错误次数
+    maxRetryCount: 5
+    # 密码锁定时间(默认10分钟)
+    lockTime: 10
+
 # Spring配置
 spring:
   application:

+ 5 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java

@@ -62,6 +62,11 @@ public interface Constants {
      */
     String LOGIN_FAIL = "Error";
 
+    /**
+     * 验证码有效期(分钟)
+     */
+    Integer CAPTCHA_EXPIRATION = 2;
+
     /**
      * 令牌
      */

+ 3 - 0
ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/config/SmsConfig.java

@@ -6,6 +6,7 @@ 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;
@@ -21,6 +22,7 @@ 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 {
 
@@ -32,6 +34,7 @@ public class SmsConfig {
     }
 
     @Configuration
+    @ConditionalOnProperty(value = "sms.enabled", havingValue = "true")
     @ConditionalOnClass(com.tencentcloudapi.sms.v20190711.SmsClient.class)
     static class TencentSmsConfig {
 

+ 2 - 0
ruoyi-common/ruoyi-common-sms/src/main/java/com/ruoyi/common/sms/config/properties/SmsProperties.java

@@ -13,6 +13,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 @ConfigurationProperties(prefix = "sms")
 public class SmsProperties {
 
+    private Boolean enabled;
+
     /**
      * 配置节点
      * 阿里云 dysmsapi.aliyuncs.com

+ 4 - 5
ruoyi-modules/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/SmsController.java

@@ -1,9 +1,8 @@
 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;
@@ -27,7 +26,7 @@ import java.util.Map;
 @RequestMapping("/demo/sms")
 public class SmsController {
 
-    private final ConfigService configService;
+    private final SmsProperties smsProperties;
 //    private final SmsTemplate smsTemplate; // 可以使用spring注入
 //    private final AliyunSmsTemplate smsTemplate; // 也可以注入某个厂家的模板工具
 
@@ -39,7 +38,7 @@ public class SmsController {
      */
     @GetMapping("/sendAliyun")
     public R<Object> sendAliyun(String phones, String templateId) {
-        if (!Convert.toBool(configService.getConfigValue("sys.account.smsEnabled"))) {
+        if (!smsProperties.getEnabled()) {
             return R.fail("当前系统没有开启短信功能!");
         }
         if (!SpringUtils.containsBean("aliyunSmsTemplate")) {
@@ -60,7 +59,7 @@ public class SmsController {
      */
     @GetMapping("/sendTencent")
     public R<Object> sendTencent(String phones, String templateId) {
-        if (!Convert.toBool(configService.getConfigValue("sys.account.smsEnabled"))) {
+        if (!smsProperties.getEnabled()) {
             return R.fail("当前系统没有开启短信功能!");
         }
         if (!SpringUtils.containsBean("tencentSmsTemplate")) {

+ 0 - 6
script/sql/oracle/oracle_ry_vue_5.X.sql

@@ -827,13 +827,7 @@ comment on column sys_config.remark        is '备注';
 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.captchaExpired',     '2',            'Y', 103, 1, sysdate, null, NULL, '验证码有效期(分钟)');
 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(10, '000000', '账号自助-邮件开关',            'sys.account.emailEnabled',      '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:关闭');
 
 

+ 0 - 6
script/sql/postgres/postgres_ry_vue_5.X.sql

@@ -848,13 +848,7 @@ comment on column sys_config.remark         is '备注';
 insert into sys_config values(1, '000000', '主框架页-默认皮肤样式名称',     '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, '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(4, '000000', '用户配置-验证码有效期',         'sys.account.captchaExpired',     '2',            'Y', 103, 1, now(), null, NULL, '验证码有效期(分钟)');
 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(10, '000000', '账号自助-邮件开关',            'sys.account.emailEnabled',      'false',         'Y', 103, 1, now(), null, NULL, '是否开启邮件功能(true开启,false关闭)');
 insert into sys_config values(11, '000000', 'OSS预览列表资源开关',          'sys.oss.previewListResource',   'true',          'Y', 103, 1, now(), null, null, 'true:开启, false:关闭');
 
 

+ 6 - 11
script/sql/ry_vue_5.X.sql

@@ -625,17 +625,12 @@ 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(4, '000000', '用户配置-验证码有效期',        'sys.account.captchaExpired',  '2',         'Y', 103, 1, sysdate(), null, NULL, '验证码有效期(分钟)');
-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(10, '000000', '账号自助-邮件开关',           'sys.account.emailEnabled',    '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(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:关闭');
+
 
 -- ----------------------------
 -- 14、系统访问记录

+ 0 - 12
script/sql/sqlserver/sqlserver_ry_vue_5.X.sql

@@ -694,20 +694,8 @@ INSERT sys_config VALUES (2, N'000000', N'用户管理-账号初始密码', N'sy
 GO
 INSERT sys_config VALUES (3, N'000000', N'主框架页-侧边栏主题', N'sys.index.sideTheme', N'theme-dark', N'Y', 103, 1, getdate(), NULL, NULL, N'深色主题theme-dark,浅色主题theme-light')
 GO
-INSERT sys_config VALUES (4, N'000000', N'用户配置-验证码有效期', N'sys.account.captchaExpired', N'2', N'Y', 103, 1, sysdate(), null, NULL, N'验证码有效期(分钟)');
-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 (10, N'000000', N'账号自助-邮件开关', N'sys.account.emailEnabled', N'false', N'Y', 103, 1, getdate(), NULL, NULL, N'是否开启邮件功能(true开启,false关闭)')
-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