浏览代码

初始密码支持自定义修改策略

RuoYi 4 年之前
父节点
当前提交
e0523d1c2d

+ 2 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java

@@ -46,8 +46,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);
 
         // 菜单导航显示风格
         String menuStyle = configService.selectConfigByKey("sys.index.menuStyle");

+ 2 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysProfileController.java

@@ -16,6 +16,7 @@ import com.ruoyi.common.config.Global;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
 import com.ruoyi.framework.shiro.service.SysPasswordService;
 import com.ruoyi.framework.util.ShiroUtils;
@@ -79,7 +80,6 @@ public class SysProfileController extends BaseController
     @ResponseBody
     public AjaxResult resetPwd(String oldPassword, String newPassword)
     {
-        
         SysUser user = ShiroUtils.getSysUser();
         if (!passwordService.matches(user, oldPassword))
         {
@@ -91,14 +91,13 @@ public class SysProfileController extends BaseController
         }
         user.setSalt(ShiroUtils.randomSalt());
         user.setPassword(passwordService.encryptPassword(user.getLoginName(), newPassword, user.getSalt()));
+        user.setPwdUpdateDate(DateUtils.getNowDate());
         if (userService.resetUserPwd(user) > 0)
         {
             ShiroUtils.setSysUser(userService.selectUserById(user.getUserId()));
             return success();
         }
         return error("修改密码异常,请联系管理员");
-        
-        
     }
 
     /**

+ 13 - 0
ruoyi-admin/src/main/resources/templates/index-topnav.html

@@ -391,6 +391,19 @@ $(function() {
 	    	$(".navbar-toolbar li a").eq(0).click();
 	    }
 	}
+	
+	/* 初始密码提示 */
+	if([[${initPasswordModify}]] == 1 && [[${isDefaultPwd}]] == true) {
+		layer.confirm("您的密码还是初始密码,请修改密码!", {
+			icon: 0,
+			title: "安全提示",
+			btn: ['确认'	, '取消'],
+			offset: ['30%']
+		}, function (index) {
+			resetPwd();
+			layer.close(index);
+		});
+	}
 });
 </script>
 </body>

+ 13 - 0
ruoyi-admin/src/main/resources/templates/index.html

@@ -331,6 +331,19 @@ $(function() {
 	    	}
 	    }
 	}
+	
+	/* 初始密码提示 */
+	if([[${initPasswordModify}]] == 1 && [[${isDefaultPwd}]] == true) {
+		layer.confirm("您的密码还是初始密码,请修改密码!", {
+			icon: 0,
+			title: "安全提示",
+			btn: ['确认'	, '取消'],
+			offset: ['30%']
+		}, function (index) {
+			resetPwd();
+			layer.close(index);
+		});
+	}
 });
 </script>
 </body>

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java

@@ -40,7 +40,7 @@ public class GenConstants
 
     /** 数据库数字类型 */
     public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer",
-            "bit","bigint", "float", "float", "double", "decimal" };
+            "bit", "bigint", "float", "float", "double", "decimal" };
 
     /** 页面不需要编辑字段 */
     public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" };

+ 13 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java

@@ -82,6 +82,9 @@ public class SysUser extends BaseEntity
     @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
     private Date loginDate;
 
+    /** 密码最后更新时间 */
+    private Date pwdUpdateDate;
+
     /** 部门对象 */
     @Excels({
         @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
@@ -294,6 +297,16 @@ public class SysUser extends BaseEntity
         this.loginDate = loginDate;
     }
 
+    public Date getPwdUpdateDate()
+    {
+        return pwdUpdateDate;
+    }
+
+    public void setPwdUpdateDate(Date pwdUpdateDate)
+    {
+        this.pwdUpdateDate = pwdUpdateDate;
+    }
+
     public SysDept getDept()
     {
         if (dept == null)

+ 24 - 22
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -5,27 +5,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 <mapper namespace="com.ruoyi.system.mapper.SysUserMapper">
 
 	<resultMap type="SysUser" id="SysUserResult">
-		<id     property="userId"       column="user_id"      />
-		<result property="deptId"       column="dept_id"      />
-		<result property="loginName"    column="login_name"   />
-		<result property="userName"     column="user_name"    />
-		<result property="userType"     column="user_type"    />
-		<result property="email"        column="email"        />
-		<result property="phonenumber"  column="phonenumber"  />
-		<result property="sex"          column="sex"          />
-		<result property="avatar"       column="avatar"       />
-		<result property="password"     column="password"     />
-		<result property="salt"         column="salt"         />
-		<result property="status"       column="status"       />
-		<result property="delFlag"      column="del_flag"     />
-		<result property="loginIp"      column="login_ip"     />
-		<result property="loginDate"    column="login_date"   />
-		<result property="createBy"     column="create_by"    />
-		<result property="createTime"   column="create_time"  />
-		<result property="updateBy"     column="update_by"    />
-		<result property="updateTime"   column="update_time"  />
-		<result property="remark"       column="remark"       />
-		<association property="dept"    column="dept_id" javaType="SysDept" resultMap="deptResult" />
+		<id     property="userId"        column="user_id"         />
+		<result property="deptId"        column="dept_id"         />
+		<result property="loginName"     column="login_name"      />
+		<result property="userName"      column="user_name"       />
+		<result property="userType"      column="user_type"       />
+		<result property="email"         column="email"           />
+		<result property="phonenumber"   column="phonenumber"     />
+		<result property="sex"           column="sex"             />
+		<result property="avatar"        column="avatar"          />
+		<result property="password"      column="password"        />
+		<result property="salt"          column="salt"            />
+		<result property="status"        column="status"          />
+		<result property="delFlag"       column="del_flag"        />
+		<result property="loginIp"       column="login_ip"        />
+		<result property="loginDate"     column="login_date"      />
+		<result property="pwdUpdateDate" column="pwd_update_date" />
+		<result property="createBy"      column="create_by"       />
+		<result property="createTime"    column="create_time"     />
+		<result property="updateBy"      column="update_by"       />
+		<result property="updateTime"    column="update_time"     />
+		<result property="remark"        column="remark"          />
+		<association property="dept"     column="dept_id" javaType="SysDept" resultMap="deptResult" />
 		<collection  property="roles"   javaType="java.util.List"        resultMap="RoleResult" />
 	</resultMap>
 	
@@ -48,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</resultMap>
 	
 	<sql id="selectUserVo">
-        select  u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.sex, u.password, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.create_time, u.remark,
+        select  u.user_id, u.dept_id, u.login_name, u.user_name, u.user_type, u.email, u.avatar, u.phonenumber, u.sex, u.password, u.salt, u.status, u.del_flag, u.login_ip, u.login_date, u.pwd_update_date, u.create_time, u.remark,
        		    d.dept_id, d.parent_id, d.dept_name, d.order_num, d.leader, d.status as dept_status,
        		    r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
 		from sys_user u
@@ -177,6 +178,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="status != null and status != ''">status = #{status},</if>
  			<if test="loginIp != null and loginIp != ''">login_ip = #{loginIp},</if>
  			<if test="loginDate != null">login_date = #{loginDate},</if>
+ 			<if test="pwdUpdateDate != null">pwd_update_date = #{pwdUpdateDate},</if>
  			<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  			<if test="remark != null">remark = #{remark},</if>
  			update_time = sysdate()

+ 6 - 4
sql/ry_20201015.sql

@@ -55,6 +55,7 @@ create table sys_user (
   del_flag          char(1)         default '0'                comment '删除标志(0代表存在 2代表删除)',
   login_ip          varchar(50)     default ''                 comment '最后登录IP',
   login_date        datetime                                   comment '最后登录时间',
+  pwd_update_date   datetime                                   comment '密码最后更新时间',
   create_by         varchar(64)     default ''                 comment '创建者',
   create_time       datetime                                   comment '创建时间',
   update_by         varchar(64)     default ''                 comment '更新者',
@@ -66,8 +67,8 @@ create table sys_user (
 -- ----------------------------
 -- 初始化-用户信息表数据
 -- ----------------------------
-insert into sys_user values(1,  103, 'admin', '若依', '00', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', '0', '0', '127.0.0.1', sysdate(), 'admin', sysdate(), '', null, '管理员');
-insert into sys_user values(2,  105, 'ry',    '若依', '00', 'ry@qq.com',  '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', '0', '0', '127.0.0.1', sysdate(), 'admin', sysdate(), '', null, '测试员');
+insert into sys_user values(1,  103, 'admin', '若依', '00', 'ry@163.com', '15888888888', '1', '', '29c67a30398638269fe600f73a054934', '111111', '0', '0', '127.0.0.1', sysdate(), sysdate(), 'admin', sysdate(), '', null, '管理员');
+insert into sys_user values(2,  105, 'ry',    '若依', '00', 'ry@qq.com',  '15666666666', '1', '', '8e6d98b90472783cc73c17047ddccf36', '222222', '0', '0', '127.0.0.1', sysdate(), sysdate(), 'admin', sysdate(), '', null, '测试员');
 
 
 -- ----------------------------
@@ -536,8 +537,9 @@ insert into sys_config values(2, '用户管理-账号初始密码',         'sys
 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.index.menuStyle',            'default',       'Y', 'admin', sysdate(), '', null, '菜单导航显示风格(default为左侧导航菜单,topnav为顶部导航菜单)');
-insert into sys_config values(7, '主框架页-是否开启页脚',         'sys.index.ignoreFooter',         'true',          'Y', 'admin', sysdate(), '', null, '是否开启底部页脚显示(true显示,false隐藏)');
+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隐藏)');
 
 
 -- ----------------------------