Commit d08cb9ee39207d204f0a0024a5d2ac64eea977b6

Authored by 徐烜
1 parent 7c9a0596

登录时判定密码是否过期,目前写死(30天有效)

src/main/java/com/bsth/controller/sys/UserController.java
@@ -12,6 +12,9 @@ import com.bsth.service.sys.CompanyAuthorityService; @@ -12,6 +12,9 @@ import com.bsth.service.sys.CompanyAuthorityService;
12 import com.bsth.service.sys.SysUserService; 12 import com.bsth.service.sys.SysUserService;
13 import com.google.common.collect.ArrayListMultimap; 13 import com.google.common.collect.ArrayListMultimap;
14 import org.apache.commons.lang3.StringUtils; 14 import org.apache.commons.lang3.StringUtils;
  15 +import org.joda.time.DateTime;
  16 +import org.joda.time.Period;
  17 +import org.joda.time.PeriodType;
15 import org.slf4j.Logger; 18 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory; 19 import org.slf4j.LoggerFactory;
17 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
@@ -101,6 +104,15 @@ public class UserController extends BaseController<SysUser, Integer> { @@ -101,6 +104,15 @@ public class UserController extends BaseController<SysUser, Integer> {
101 return rs; 104 return rs;
102 } 105 }
103 106
  107 + // 检验密码有效期
  108 + Date lastPwdDate = user.getLastPwdDate();
  109 + if (lastPwdDate != null) {
  110 + Period p = new Period(new DateTime(lastPwdDate), new DateTime(new Date()), PeriodType.days());
  111 + if (p.getDays() > 30) { // 30天不更新密码,不能登录
  112 + return put(rs, "msg", "30天没有修改密码,不能登录,请联系管理员");
  113 + }
  114 + }
  115 +
104 // 登录 116 // 登录
105 SecurityUtils.login(user, request); 117 SecurityUtils.login(user, request);
106 //session里写入用户名,webSocket连接时标识身份用 118 //session里写入用户名,webSocket连接时标识身份用
src/main/java/com/bsth/entity/sys/SysUser.java
@@ -33,6 +33,9 @@ public class SysUser { @@ -33,6 +33,9 @@ public class SysUser {
33 @Column(name = "last_loginDate", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") 33 @Column(name = "last_loginDate", columnDefinition = "timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
34 private Date lastLoginDate; 34 private Date lastLoginDate;
35 35
  36 + /** 最近密码更新时间 */
  37 + private Date lastPwdDate;
  38 +
36 private String agencies; 39 private String agencies;
37 40
38 private boolean enabled; 41 private boolean enabled;
@@ -112,4 +115,12 @@ public class SysUser { @@ -112,4 +115,12 @@ public class SysUser {
112 public void setRoles(Set<Role> roles) { 115 public void setRoles(Set<Role> roles) {
113 this.roles = roles; 116 this.roles = roles;
114 } 117 }
  118 +
  119 + public Date getLastPwdDate() {
  120 + return lastPwdDate;
  121 + }
  122 +
  123 + public void setLastPwdDate(Date lastPwdDate) {
  124 + this.lastPwdDate = lastPwdDate;
  125 + }
115 } 126 }
src/main/java/com/bsth/repository/sys/SysUserRepository.java
@@ -22,7 +22,7 @@ public interface SysUserRepository extends BaseRepository&lt;SysUser, Integer&gt;{ @@ -22,7 +22,7 @@ public interface SysUserRepository extends BaseRepository&lt;SysUser, Integer&gt;{
22 22
23 @Transactional 23 @Transactional
24 @Modifying 24 @Modifying
25 - @Query(value="update bsth_c_sys_user set password=?2 where id=?1",nativeQuery=true) 25 + @Query(value="update bsth_c_sys_user set password=?2, last_pwd_date = now() where id=?1",nativeQuery=true)
26 int changePWD(int id,String newPWD); 26 int changePWD(int id,String newPWD);
27 27
28 @EntityGraph(value = "sysUser_role", type = EntityGraph.EntityGraphType.FETCH) 28 @EntityGraph(value = "sysUser_role", type = EntityGraph.EntityGraphType.FETCH)