Browse Source

feat: 账户密码登录三次错误后必须输入验证码

TwoKe945 1 năm trước cách đây
mục cha
commit
ede15bbc55

+ 3 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java

@@ -2,6 +2,8 @@ package com.ruoyi.web.controller.system;
 
 import java.util.List;
 import java.util.Set;
+
+import com.ruoyi.framework.web.service.SysPasswordService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
@@ -28,6 +30,7 @@ public class SysLoginController
     @Autowired
     private SysLoginService loginService;
 
+
     @Autowired
     private ISysMenuService menuService;
 

+ 2 - 2
ruoyi-admin/src/main/resources/application.yml

@@ -43,9 +43,9 @@ logging:
 user:
   password:
     # 密码最大错误次数
-    maxRetryCount: 5
+    maxRetryCount: 3
     # 密码锁定时间(默认10分钟)
-    lockTime: 10
+    lockTime: 0
 
 # Spring配置
 spring:

+ 1 - 1
ruoyi-admin/src/main/resources/i18n/messages.properties

@@ -5,7 +5,7 @@ user.jcaptcha.expire=验证码已失效
 user.not.exists=用户不存在/密码错误
 user.password.not.match=用户不存在/密码错误
 user.password.retry.limit.count=密码输入错误{0}次
-user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定{1}分钟
+user.password.retry.limit.exceed=密码输入错误{0}次
 user.password.delete=对不起,您的账号已被删除
 user.blocked=用户已封禁,请联系管理员
 role.blocked=角色已封禁,请联系管理员

+ 110 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -61,6 +61,43 @@ public class SysUser extends BaseEntity
 
     /** 删除标志(0代表存在 2代表删除) */
     private String delFlag;
+    /**
+     * 出生日期
+     */
+    private Date birthday;
+    /**
+     * 身份证号
+     */
+    private String idCard;
+    /**
+     * 身高
+     */
+    private Integer height;
+    /**
+     * 家庭住址
+     */
+    private String familyAddress;
+    /**
+     * 政治面貌
+     */
+    private String politicalStatus;
+    /**
+     * 入职时间
+     */
+    private Date hiredate;
+    /**
+     * 入党时间
+     */
+    private Date partyMembershipDate;
+    /**
+     * 衔级
+     */
+    private String rank;
+    /**
+     * 持有证照
+     */
+    private String holdDocuments;
+
 
     /** 最后登录IP */
     @Excel(name = "最后登录IP", type = Type.EXPORT)
@@ -70,6 +107,79 @@ public class SysUser extends BaseEntity
     @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
     private Date loginDate;
 
+
+    public Date getBirthday() {
+        return birthday;
+    }
+
+    public void setBirthday(Date birthday) {
+        this.birthday = birthday;
+    }
+
+    public String getIdCard() {
+        return idCard;
+    }
+
+    public void setIdCard(String idCard) {
+        this.idCard = idCard;
+    }
+
+    public Integer getHeight() {
+        return height;
+    }
+
+    public void setHeight(Integer height) {
+        this.height = height;
+    }
+
+    public String getFamilyAddress() {
+        return familyAddress;
+    }
+
+    public void setFamilyAddress(String familyAddress) {
+        this.familyAddress = familyAddress;
+    }
+
+    public String getPoliticalStatus() {
+        return politicalStatus;
+    }
+
+    public void setPoliticalStatus(String politicalStatus) {
+        this.politicalStatus = politicalStatus;
+    }
+
+    public Date getHiredate() {
+        return hiredate;
+    }
+
+    public void setHiredate(Date hiredate) {
+        this.hiredate = hiredate;
+    }
+
+    public Date getPartyMembershipDate() {
+        return partyMembershipDate;
+    }
+
+    public void setPartyMembershipDate(Date partyMembershipDate) {
+        this.partyMembershipDate = partyMembershipDate;
+    }
+
+    public String getRank() {
+        return rank;
+    }
+
+    public void setRank(String rank) {
+        this.rank = rank;
+    }
+
+    public String getHoldDocuments() {
+        return holdDocuments;
+    }
+
+    public void setHoldDocuments(String holdDocuments) {
+        this.holdDocuments = holdDocuments;
+    }
+
     /** 部门对象 */
     @Excels({
         @Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),

+ 6 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java

@@ -52,6 +52,8 @@ public class SysLoginService
     @Autowired
     private ISysConfigService configService;
 
+    @Autowired
+    private SysPasswordService sysPasswordService;
     /**
      * 登录验证
      * 
@@ -63,8 +65,10 @@ public class SysLoginService
      */
     public String login(String username, String password, String code, String uuid)
     {
-        // 验证码校验
-        validateCaptcha(username, code, uuid);
+        if (sysPasswordService.needCode(username)) {
+            // 验证码校验
+            validateCaptcha(username, code, uuid);
+        }
         // 登录前置校验
         loginPreCheck(username, password);
         // 用户验证

+ 19 - 7
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPasswordService.java

@@ -1,6 +1,8 @@
 package com.ruoyi.framework.web.service;
 
 import java.util.concurrent.TimeUnit;
+
+import com.ruoyi.common.exception.user.UserException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.core.Authentication;
@@ -45,6 +47,15 @@ public class SysPasswordService
         return CacheConstants.PWD_ERR_CNT_KEY + username;
     }
 
+    public boolean needCode(String username) {
+        Integer retryCount = redisCache.getCacheObject(getCacheKey(username));
+        if (retryCount == null)
+        {
+            retryCount = 0;
+        }
+        return retryCount >= Integer.valueOf(maxRetryCount).intValue();
+    }
+
     public void validate(SysUser user)
     {
         Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext();
@@ -58,19 +69,20 @@ public class SysPasswordService
             retryCount = 0;
         }
 
-        if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
-        {
-            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
-                    MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount, lockTime)));
-            throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime);
-        }
+//        if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
+//        {
+//            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
+//                    MessageUtils.message("user.password.retry.limit.exceed", maxRetryCount, lockTime)));
+//            throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime);
+//            throw new UserException("user.password.retry.limit.count", new Object[]{ retryCount });
+//        }
 
         if (!matches(user, password))
         {
             retryCount = retryCount + 1;
             AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL,
                     MessageUtils.message("user.password.retry.limit.count", retryCount)));
-            redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
+             redisCache.setCacheObject(getCacheKey(username), retryCount);
             throw new UserPasswordNotMatchException();
         }
         else

+ 41 - 10
ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -23,7 +23,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <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" />
+        <result property="birthday"     column="birthday"       />
+        <result property="idCard"       column="id_card"       />
+        <result property="height"       column="height"       />
+        <result property="familyAddress"   column="family_address"       />
+        <result property="politicalStatus" column="political_status"       />
+        <result property="hiredate"   column="hiredate"       />
+        <result property="partyMembershipDate"  column="party_membership_date"       />
+        <result property="rank"  column="rank"       />
+        <result property="holdDocuments"  column="hold_documents"   />
+		<association property="dept"    column="dept_id" javaType="SysDept" resultMap="deptResult" />
         <collection  property="roles"   javaType="java.util.List"           resultMap="RoleResult" />
     </resultMap>
 	
@@ -49,15 +58,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<sql id="selectUserVo">
         select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, 
         d.dept_id, d.parent_id, d.ancestors, 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
+        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,
+			u.birthday,u.id_card,u.height,u.family_address,u.political_status,u.hiredate,u.party_membership_date,u.rank,u.hold_documents
+		from sys_user u
 		    left join sys_dept d on u.dept_id = d.dept_id
 		    left join sys_user_role ur on u.user_id = ur.user_id
 		    left join sys_role r on r.role_id = ur.role_id
     </sql>
     
     <select id="selectUserList" parameterType="SysUser" resultMap="SysUserResult">
-		select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader from sys_user u
+		select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader,
+		u.birthday,u.id_card,u.height,u.family_address,u.political_status,u.hiredate,u.party_membership_date,u.rank,u.hold_documents
+		from sys_user u
 		left join sys_dept d on u.dept_id = d.dept_id
 		where u.del_flag = '0'
 		<if test="userId != null and userId != 0">
@@ -86,8 +98,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 	
 	<select id="selectAllocatedList" parameterType="SysUser" resultMap="SysUserResult">
-	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
-	    from sys_user u
+	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time,
+		u.birthday,u.id_card,u.height,u.family_address,u.political_status,u.hiredate,u.party_membership_date,u.rank,u.hold_documents
+		from sys_user u
 			 left join sys_dept d on u.dept_id = d.dept_id
 			 left join sys_user_role ur on u.user_id = ur.user_id
 			 left join sys_role r on r.role_id = ur.role_id
@@ -103,8 +116,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
 	
 	<select id="selectUnallocatedList" parameterType="SysUser" resultMap="SysUserResult">
-	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time
-	    from sys_user u
+	    select distinct u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, u.status, u.create_time,
+		u.birthday,u.id_card,u.height,u.family_address,u.political_status,u.hiredate,u.party_membership_date,u.rank,u.hold_documents
+		from sys_user u
 			 left join sys_dept d on u.dept_id = d.dept_id
 			 left join sys_user_role ur on u.user_id = ur.user_id
 			 left join sys_role r on r.role_id = ur.role_id
@@ -141,7 +155,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
 		select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
 	</select>
-	
 	<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
  		insert into sys_user(
  			<if test="userId != null and userId != 0">user_id,</if>
@@ -155,7 +168,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="password != null and password != ''">password,</if>
  			<if test="status != null and status != ''">status,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
- 			<if test="remark != null and remark != ''">remark,</if>
+ 			<if test="remark != null">remark,</if>
+			<if test="birthday!= null">birthday,</if>
+			<if test="idCard!= null">id_card,</if>
+			<if test="height!= null">height,</if>
+			<if test="familyAddress!= null">family_address,</if>
+			<if test="politicalStatus!= null ">political_status,</if>
+			<if test="hiredate!= null ">hiredate,</if>
+			<if test="partyMembershipDate!= null">party_membership_date,</if>
+			<if test="rank!= null">rank,</if>
+			<if test="holdDocuments!= null">hold_documents,</if>
  			create_time
  		)values(
  			<if test="userId != null and userId != ''">#{userId},</if>
@@ -170,6 +192,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="status != null and status != ''">#{status},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
  			<if test="remark != null and remark != ''">#{remark},</if>
+			<if test="birthday!= null">#{birthday},</if>
+			<if test="idCard!= null">#{idCard},</if>
+			<if test="height!= null">#{height},</if>
+			<if test="familyAddress!= null">#{familyAddress},</if>
+			<if test="politicalStatus!= null ">#{politicalStatus},</if>
+			<if test="hiredate!= null ">#{hiredate},</if>
+			<if test="partyMembershipDate!= null">#{partyMembershipDate},</if>
+			<if test="rank!= null">#{rank},</if>
+			<if test="holdDocuments!= null">#{holdDocuments},</if>
  			sysdate()
  		)
 	</insert>