From 471c8825bab22d5506d09e04ee761ea05ef8672b Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 15 Oct 2020 17:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E5=8F=B7=E5=AF=86=E7=A0=81=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=E6=9B=B4=E6=96=B0=E5=91=A8?= =?UTF-8?q?=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysIndexController.java | 31 +++++++++++++++++-- .../resources/templates/index-topnav.html | 15 ++++++++- .../src/main/resources/templates/index.html | 15 ++++++++- .../templates/system/config/config.html | 2 +- .../templates/system/dict/type/type.html | 2 +- .../com/ruoyi/common/utils/DateUtils.java | 8 +++++ sql/ry_20201015.sql | 17 +++++----- 7 files changed, 76 insertions(+), 14 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java index 1c1070034..775bc5dc3 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java @@ -1,5 +1,6 @@ package com.ruoyi.web.controller.system; +import java.util.Date; import java.util.List; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; @@ -10,7 +11,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import com.ruoyi.common.config.Global; import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.utils.CookieUtils; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.util.ShiroUtils; @@ -46,10 +49,10 @@ public class SysIndexController extends BaseController mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme")); mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName")); mmap.put("ignoreFooter", configService.selectConfigByKey("sys.index.ignoreFooter")); - mmap.put("initPasswordModify", configService.selectConfigByKey("sys.account.initPasswordModify")); mmap.put("copyrightYear", Global.getCopyrightYear()); mmap.put("demoEnabled", Global.isDemoEnabled()); - mmap.put("isDefaultPwd", user.getPwdUpdateDate() == null); + mmap.put("isDefaultModifyPwd", initPasswordIsModify(user.getPwdUpdateDate())); + mmap.put("isPasswordExpired", passwordIsExpiration(user.getPwdUpdateDate())); // 菜单导航显示风格 String menuStyle = configService.selectConfigByKey("sys.index.menuStyle"); @@ -91,4 +94,28 @@ public class SysIndexController extends BaseController mmap.put("version", Global.getVersion()); return "main"; } + + // 检查初始密码是否提醒修改 + public boolean initPasswordIsModify(Date pwdUpdateDate) + { + int initPasswordModify = Convert.toInt(configService.selectConfigByKey("sys.account.initPasswordModify")); + return initPasswordModify == 1 && pwdUpdateDate == null; + } + + // 检查密码是否过期 + public boolean passwordIsExpiration(Date pwdUpdateDate) + { + int passwordValidataDays = Convert.toInt(configService.selectConfigByKey("sys.account.passwordValidataDays")); + if (passwordValidataDays > 0) + { + if (StringUtils.isNull(pwdUpdateDate)) + { + // 如果从未修改过初始密码,直接提醒过期 + return true; + } + Date nowDate = DateUtils.getNowDate(); + return DateUtils.differentDaysByMillisecond(nowDate, pwdUpdateDate) > passwordValidataDays; + } + return false; + } } diff --git a/ruoyi-admin/src/main/resources/templates/index-topnav.html b/ruoyi-admin/src/main/resources/templates/index-topnav.html index 92ef138bb..70126f863 100644 --- a/ruoyi-admin/src/main/resources/templates/index-topnav.html +++ b/ruoyi-admin/src/main/resources/templates/index-topnav.html @@ -393,7 +393,7 @@ $(function() { } /* 初始密码提示 */ - if([[${initPasswordModify}]] == 1 && [[${isDefaultPwd}]] == true) { + if([[${isDefaultModifyPwd}]]) { layer.confirm("您的密码还是初始密码,请修改密码!", { icon: 0, title: "安全提示", @@ -404,6 +404,19 @@ $(function() { layer.close(index); }); } + + /* 过期密码提示 */ + if([[${isPasswordExpired}]]) { + layer.confirm("您的密码已过期,请尽快修改密码!", { + icon: 0, + title: "安全提示", + btn: ['确认' , '取消'], + offset: ['30%'] + }, function (index) { + resetPwd(); + layer.close(index); + }); + } }); diff --git a/ruoyi-admin/src/main/resources/templates/index.html b/ruoyi-admin/src/main/resources/templates/index.html index c51115aaa..68fac176e 100644 --- a/ruoyi-admin/src/main/resources/templates/index.html +++ b/ruoyi-admin/src/main/resources/templates/index.html @@ -333,7 +333,7 @@ $(function() { } /* 初始密码提示 */ - if([[${initPasswordModify}]] == 1 && [[${isDefaultPwd}]] == true) { + if([[${isDefaultModifyPwd}]]) { layer.confirm("您的密码还是初始密码,请修改密码!", { icon: 0, title: "安全提示", @@ -344,6 +344,19 @@ $(function() { layer.close(index); }); } + + /* 过期密码提示 */ + if([[${isPasswordExpired}]]) { + layer.confirm("您的密码已过期,请尽快修改密码!", { + icon: 0, + title: "安全提示", + btn: ['确认' , '取消'], + offset: ['30%'] + }, function (index) { + resetPwd(); + layer.close(index); + }); + } }); diff --git a/ruoyi-admin/src/main/resources/templates/system/config/config.html b/ruoyi-admin/src/main/resources/templates/system/config/config.html index d2ef99626..e4f5306c6 100644 --- a/ruoyi-admin/src/main/resources/templates/system/config/config.html +++ b/ruoyi-admin/src/main/resources/templates/system/config/config.html @@ -74,7 +74,7 @@ removeUrl: prefix + "/remove", exportUrl: prefix + "/export", sortName: "createTime", - sortOrder: "desc", + sortOrder: "asc", modalName: "参数", columns: [{ checkbox: true diff --git a/ruoyi-admin/src/main/resources/templates/system/dict/type/type.html b/ruoyi-admin/src/main/resources/templates/system/dict/type/type.html index fb761d15e..29b7b8878 100644 --- a/ruoyi-admin/src/main/resources/templates/system/dict/type/type.html +++ b/ruoyi-admin/src/main/resources/templates/system/dict/type/type.html @@ -76,7 +76,7 @@ removeUrl: prefix + "/remove", exportUrl: prefix + "/export", sortName: "createTime", - sortOrder: "desc", + sortOrder: "asc", modalName: "类型", columns: [{ checkbox: true diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index 8ff95f1b7..4b45f35bd 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -131,6 +131,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils return new Date(time); } + /** + * 计算相差天数 + */ + public static int differentDaysByMillisecond(Date date1, Date date2) + { + return Math.abs((int) ((date2.getTime() - date1.getTime()) / (1000 * 3600 * 24))); + } + /** * 计算两个时间差 */ diff --git a/sql/ry_20201015.sql b/sql/ry_20201015.sql index c495309bf..b3b957160 100644 --- a/sql/ry_20201015.sql +++ b/sql/ry_20201015.sql @@ -532,14 +532,15 @@ create table sys_config ( primary key (config_id) ) engine=innodb auto_increment=100 comment = '参数配置表'; -insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'admin', sysdate(), '', null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow'); -insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456'); -insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深黑主题theme-dark,浅色主题theme-light,深蓝主题theme-blue'); -insert into sys_config values(4, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 'admin', sysdate(), '', null, '是否开启注册用户功能(true开启,false关闭)'); -insert into sys_config values(5, '用户管理-密码字符范围', 'sys.account.chrtype', '0', 'Y', 'admin', sysdate(), '', null, '默认任意字符范围,0任意(密码可以输入任意字符),1数字(密码只能为0-9数字),2英文字母(密码只能为a-z和A-Z字母),3字母和数字(密码必须包含字母,数字),4字母数组和特殊字符(密码必须包含字母,数字,特殊字符-_)'); -insert into sys_config values(6, '用户管理-初始密码修改策略', 'sys.account.initPasswordModify', '0', 'Y', 'admin', sysdate(), '', null, '0:初始密码修改策略关闭,没有任何提示,1:提醒用户,如果未修改初始密码,则在登录时就会提醒修改密码对话框'); -insert into sys_config values(7, '主框架页-菜单导航显示风格', 'sys.index.menuStyle', 'default', 'Y', 'admin', sysdate(), '', null, '菜单导航显示风格(default为左侧导航菜单,topnav为顶部导航菜单)'); -insert into sys_config values(8, '主框架页-是否开启页脚', 'sys.index.ignoreFooter', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启底部页脚显示(true显示,false隐藏)'); +insert into sys_config values(1, '主框架页-默认皮肤样式名称', 'sys.index.skinName', 'skin-blue', 'Y', 'admin', sysdate(), '', null, '蓝色 skin-blue、绿色 skin-green、紫色 skin-purple、红色 skin-red、黄色 skin-yellow'); +insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456'); +insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深黑主题theme-dark,浅色主题theme-light,深蓝主题theme-blue'); +insert into sys_config values(4, '账号自助-是否开启用户注册功能', 'sys.account.registerUser', 'false', 'Y', 'admin', sysdate(), '', null, '是否开启注册用户功能(true开启,false关闭)'); +insert into sys_config values(5, '用户管理-密码字符范围', 'sys.account.chrtype', '0', 'Y', 'admin', sysdate(), '', null, '默认任意字符范围,0任意(密码可以输入任意字符),1数字(密码只能为0-9数字),2英文字母(密码只能为a-z和A-Z字母),3字母和数字(密码必须包含字母,数字),4字母数组和特殊字符(密码必须包含字母,数字,特殊字符-_)'); +insert into sys_config values(6, '用户管理-初始密码修改策略', 'sys.account.initPasswordModify', '0', 'Y', 'admin', sysdate(), '', null, '0:初始密码修改策略关闭,没有任何提示,1:提醒用户,如果未修改初始密码,则在登录时就会提醒修改密码对话框'); +insert into sys_config values(7, '用户管理-账号密码更新周期', 'sys.account.passwordValidataDays', '0', 'Y', 'admin', sysdate(), '', null, '密码更新周期(填写数字,数据初始化值为0不限制,若修改必须为大于0小于365的正整数),如果超过这个周期登录系统时,则在登录时就会提醒修改密码对话框'); +insert into sys_config values(8, '主框架页-菜单导航显示风格', 'sys.index.menuStyle', 'default', 'Y', 'admin', sysdate(), '', null, '菜单导航显示风格(default为左侧导航菜单,topnav为顶部导航菜单)'); +insert into sys_config values(9, '主框架页-是否开启页脚', 'sys.index.ignoreFooter', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启底部页脚显示(true显示,false隐藏)'); -- ----------------------------