From 1ed1752f678f769e43e9faa34809701850c7f727 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 30 三月 2023 19:14:38 +0800 Subject: [PATCH] update 优化 验证码有效期 迁移到数据库 参数管理内 --- script/sql/postgres/postgres_ry_vue_5.X.sql | 10 ++++++---- ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java | 5 ----- ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java | 12 +++++++----- script/sql/ry_vue_5.X.sql | 13 +++++++------ script/sql/oracle/oracle_ry_vue_5.X.sql | 2 ++ script/sql/sqlserver/sqlserver_ry_vue_5.X.sql | 4 ++++ 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java index f3940c6..fec91b9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java @@ -6,7 +6,6 @@ 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; @@ -64,7 +63,8 @@ } String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber; String code = RandomUtil.randomNumbers(4); - RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); + Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired")); + RedisUtils.setCacheObject(key, code, Duration.ofMinutes(captchaExpired)); // 楠岃瘉鐮佹ā鏉縤d 鑷澶勭悊 (鏌ユ暟鎹簱鎴栧啓姝诲潎鍙�) String templateId = configService.selectConfigByKey("sys.account.templateId"); Map<String, String> map = new HashMap<>(1); @@ -90,9 +90,10 @@ } String key = GlobalConstants.CAPTCHA_CODE_KEY + email; String code = RandomUtil.randomNumbers(4); - RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); + Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired")); + RedisUtils.setCacheObject(key, code, Duration.ofMinutes(captchaExpired)); try { - MailUtils.sendText(email, "鐧诲綍楠岃瘉鐮�", "鎮ㄦ湰娆¢獙璇佺爜涓猴細" + code + "锛屾湁鏁堟�т负" + Constants.CAPTCHA_EXPIRATION + "鍒嗛挓锛岃灏藉揩濉啓銆�"); + MailUtils.sendText(email, "鐧诲綍楠岃瘉鐮�", "鎮ㄦ湰娆¢獙璇佺爜涓猴細%s锛屾湁鏁堟�т负%d鍒嗛挓锛岃灏藉揩濉啓銆�".formatted(code, captchaExpired)); } catch (Exception e) { log.error("楠岃瘉鐮佺煭淇″彂閫佸紓甯� => {}", e.getMessage()); return R.fail(e.getMessage()); @@ -128,7 +129,8 @@ Expression exp = parser.parseExpression(StringUtils.remove(code, "=")); code = exp.getValue(String.class); } - RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION)); + Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired")); + RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(captchaExpired)); captchaVo.setUuid(uuid); captchaVo.setImg(captcha.getImageBase64()); return R.ok(captchaVo); diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java index 9553d17..203be87 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/Constants.java @@ -63,11 +63,6 @@ String LOGIN_FAIL = "Error"; /** - * 楠岃瘉鐮佹湁鏁堟湡锛堝垎閽燂級 - */ - Integer CAPTCHA_EXPIRATION = 2; - - /** * 浠ょ墝 */ String TOKEN = "token"; diff --git a/script/sql/oracle/oracle_ry_vue_5.X.sql b/script/sql/oracle/oracle_ry_vue_5.X.sql index 4c7c56a..2c3ceb2 100644 --- a/script/sql/oracle/oracle_ry_vue_5.X.sql +++ b/script/sql/oracle/oracle_ry_vue_5.X.sql @@ -827,11 +827,13 @@ 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锛屾祬鑹蹭富棰榯heme-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', '璐﹀彿鑷姪-楠岃瘉鐮佹ā鏉縤d', 'sys.account.templateId', '', 'Y', 103, 1, sysdate, null, null, '楠岃瘉鐮佹ā鏉縤d'); +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:鍏抽棴'); diff --git a/script/sql/postgres/postgres_ry_vue_5.X.sql b/script/sql/postgres/postgres_ry_vue_5.X.sql index 5e394a0..037b1b2 100644 --- a/script/sql/postgres/postgres_ry_vue_5.X.sql +++ b/script/sql/postgres/postgres_ry_vue_5.X.sql @@ -848,11 +848,13 @@ 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锛屾祬鑹蹭富棰榯heme-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', '璐﹀彿鑷姪-楠岃瘉鐮佹ā鏉縤d', 'sys.account.templateId', '', 'Y', 103, 1, now(), null, null, '楠岃瘉鐮佹ā鏉縤d'); +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', '璐﹀彿鑷姪-楠岃瘉鐮佹ā鏉縤d', 'sys.account.templateId', '', 'Y', 103, 1, now(), null, null, '楠岃瘉鐮佹ā鏉縤d'); +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:鍏抽棴'); diff --git a/script/sql/ry_vue_5.X.sql b/script/sql/ry_vue_5.X.sql index 41290d2..ca4fe11 100644 --- a/script/sql/ry_vue_5.X.sql +++ b/script/sql/ry_vue_5.X.sql @@ -628,13 +628,14 @@ 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锛屾祬鑹蹭富棰榯heme-light'); -insert into sys_config values(4, '000000', '璐﹀彿鑷姪-楠岃瘉鐮佸紑鍏�', 'sys.account.captchaEnabled', 'true', 'Y', 103, 1, sysdate(), null, NULL, '鏄惁寮�鍚獙璇佺爜鍔熻兘锛坱rue寮�鍚紝false鍏抽棴锛�'); -insert into sys_config values(5, '000000', '璐﹀彿鑷姪-鏄惁寮�鍚敤鎴锋敞鍐屽姛鑳�', 'sys.account.registerUser', 'false', 'Y', 103, 1, sysdate(), null, NULL, '鏄惁寮�鍚敞鍐岀敤鎴峰姛鑳斤紙true寮�鍚紝false鍏抽棴锛�'); +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', '璐﹀彿鑷姪-楠岃瘉鐮佹ā鏉縤d', 'sys.account.templateId', '', 'Y', 103, 1, sysdate(), null, NULL, '楠岃瘉鐮佹ā鏉縤d'); -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(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', '璐﹀彿鑷姪-鐭俊楠岃瘉鐮佹ā鏉縤d', 'sys.account.templateId', '', 'Y', 103, 1, sysdate(), null, NULL, '楠岃瘉鐮佹ā鏉縤d'); +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:鍏抽棴'); -- ---------------------------- -- 14銆佺郴缁熻闂褰� diff --git a/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql b/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql index 53a8c07..38e2b2f 100644 --- a/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql +++ b/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql @@ -694,6 +694,8 @@ 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锛屾祬鑹蹭富棰榯heme-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'瀵嗙爜鏈�澶ч敊璇鏁�') @@ -704,6 +706,8 @@ GO INSERT sys_config VALUES (9, N'000000', N'璐﹀彿鑷姪-楠岃瘉鐮佹ā鏉縤d', N'sys.account.templateId', N'', N'Y', 103, 1, getdate(), NULL, NULL, N'楠岃瘉鐮佹ā鏉縤d') 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 -- Gitblit v1.9.3