Browse Source

登录验证码失败调整

sangwenwei 8 months ago
parent
commit
7cb590352b

+ 19 - 0
src/main/java/com/jeeplus/modules/sys/web/UserController.java

@@ -633,6 +633,25 @@ public class UserController extends BaseController {
     public ComNameJson getComName(String userName, HttpServletResponse response, Model model) {
         StringBuffer sb =new StringBuffer();
         ComNameJson j = new ComNameJson();
+        User user1 = UserUtils.getByLoginName(userName);
+        if (user1 != null){
+            //获取用户登录次数
+            String key = "loginFailNum:"+user1.getLoginName();
+            String loginFailNum = JedisUtils.getResource().get(key);
+            if (StringUtils.isNotBlank(loginFailNum)){
+                int num = Integer.parseInt(loginFailNum);
+                if (num >=5 && num <10){
+                    model.addAttribute("isValidateCodeLogin", true);
+                    j.setMsg("isValidateCodeLogin");
+                }
+                if (num >= 10){
+                    model.addAttribute("maxCount","true");
+                    j.setMsg("maxCount");
+                }
+                j.setSuccess(false);
+                return j;
+            }
+        }
         User user = userDao.getByLoginName(new User(null,userName));
         if(user == null){
             j.setMsg("用户名不存在!");

+ 13 - 3
src/main/webapp/webpage/modules/sys/sysLogin.jsp

@@ -440,6 +440,16 @@
             $.get("${ctx}/sys/user/getComName?userName="+ val,function(data){
                 if(data.success == false){
                     /*top.layer.alert(data.msg, {icon: 0});*///讨厌的白色字体问题
+					var res = data.msg;
+					if (res == 'isValidateCodeLogin'){
+						$("#validateCodeContainer").show();
+						$("#lastMsg").text("");
+					}
+					if (res == 'maxCount'){
+						$("#loginButton").attr("disabled", true);
+						$("#lastMsg").text("登录失败次数超过限制,今日无法登录.");
+						$("#validateCodeContainer").hide();
+					}
                 }else{
                     var selectItem = "<option value='{0}' > {1}</option>";     //下拉框选项
                     var selectedItem = "<option value='{0}'  selected='selected' > {1}</option>";    //默认被选择的下拉框选项
@@ -613,8 +623,8 @@
 															</span>
 													<span id="span" class="help-inline"></span>
 												</label>
-												<c:if test="${isValidateCodeLogin}">
-													<label class="block clearfix">
+<%--												<c:if test="${isValidateCodeLogin}">--%>
+													<label id="validateCodeContainer" style="display: none;">
 													<span class=" input-icon input-icon-right" style="display: flex">
 														<input type="text" style="width: 200px" id="validateCode" name="validateCode" placeholder="验证码" class="form-control required">
 															<a style="text-decoration:none;" href="javascript:void(0);" rel="external nofollow" onclick="VerificationCode()">
@@ -624,7 +634,7 @@
 													</span >
 														<span id="errorMsg" class="help-inline"></span>
 													</label>
-												</c:if>
+<%--												</c:if>--%>
 													<span id="lastMsg" class="help-inline" style="color: red;"></span>