Commit d245fadac78da8607d0ee5c8e672aabdf9efca36
1 parent
56ccdff4
1.模糊登录信息提示,修改以sessionId作为验证码的出现基准
Showing
1 changed file
with
17 additions
and
12 deletions
src/main/java/com/bsth/controller/sys/UserController.java
| @@ -57,6 +57,15 @@ public class UserController extends BaseController<SysUser, Integer> { | @@ -57,6 +57,15 @@ public class UserController extends BaseController<SysUser, Integer> { | ||
| 57 | //需要验证码的账号 | 57 | //需要验证码的账号 |
| 58 | public static Map<String, Integer> captchaMap = new HashMap<>(); | 58 | public static Map<String, Integer> captchaMap = new HashMap<>(); |
| 59 | 59 | ||
| 60 | + private static void captcha(String sessionId) { | ||
| 61 | + Integer captchSize = captchaMap.get(sessionId); | ||
| 62 | + if (null == captchSize) | ||
| 63 | + captchSize = 0; | ||
| 64 | + | ||
| 65 | + captchSize++; | ||
| 66 | + captchaMap.put(sessionId, captchSize); | ||
| 67 | + } | ||
| 68 | + | ||
| 60 | @RequestMapping(value = "/login", method = RequestMethod.POST) | 69 | @RequestMapping(value = "/login", method = RequestMethod.POST) |
| 61 | public Map<String, Object> login(HttpServletRequest request, @RequestParam String userName, | 70 | public Map<String, Object> login(HttpServletRequest request, @RequestParam String userName, |
| 62 | @RequestParam String password, String captcha) { | 71 | @RequestParam String password, String captcha) { |
| @@ -88,8 +97,10 @@ public class UserController extends BaseController<SysUser, Integer> { | @@ -88,8 +97,10 @@ public class UserController extends BaseController<SysUser, Integer> { | ||
| 88 | } | 97 | } |
| 89 | 98 | ||
| 90 | SysUser user = sysUserService.findByUserName(userName); | 99 | SysUser user = sysUserService.findByUserName(userName); |
| 91 | - if (null == user) | ||
| 92 | - return put(rs, "msg", "不存在的用户"); | 100 | + if (null == user) { |
| 101 | + captcha(session.getId()); | ||
| 102 | + return put(rs, "msg", "用户名或密码错误"); | ||
| 103 | + } | ||
| 93 | 104 | ||
| 94 | if (!user.isEnabled()) | 105 | if (!user.isEnabled()) |
| 95 | return put(rs, "msg", "该用户已被锁定,请联系管理员"); | 106 | return put(rs, "msg", "该用户已被锁定,请联系管理员"); |
| @@ -97,14 +108,8 @@ public class UserController extends BaseController<SysUser, Integer> { | @@ -97,14 +108,8 @@ public class UserController extends BaseController<SysUser, Integer> { | ||
| 97 | // 校验密码 | 108 | // 校验密码 |
| 98 | boolean matchStatus = new BCryptPasswordEncoder(4).matches(password, user.getPassword()); | 109 | boolean matchStatus = new BCryptPasswordEncoder(4).matches(password, user.getPassword()); |
| 99 | if (!matchStatus) { | 110 | if (!matchStatus) { |
| 100 | - rs.put("msg", "密码有误"); | ||
| 101 | - | ||
| 102 | - Integer captchSize = captchaMap.get(userName); | ||
| 103 | - if (null == captchSize) | ||
| 104 | - captchSize = 0; | ||
| 105 | - | ||
| 106 | - captchSize++; | ||
| 107 | - captchaMap.put(userName, captchSize); | 111 | + captcha(session.getId()); |
| 112 | + rs.put("msg", "用户名或密码错误"); | ||
| 108 | return rs; | 113 | return rs; |
| 109 | } | 114 | } |
| 110 | 115 | ||
| @@ -226,8 +231,8 @@ public class UserController extends BaseController<SysUser, Integer> { | @@ -226,8 +231,8 @@ public class UserController extends BaseController<SysUser, Integer> { | ||
| 226 | } | 231 | } |
| 227 | 232 | ||
| 228 | @RequestMapping(value = "/login/captchaStatus") | 233 | @RequestMapping(value = "/login/captchaStatus") |
| 229 | - public int captchaStatus(String userName) { | ||
| 230 | - Integer size = captchaMap.get(userName); | 234 | + public int captchaStatus(String userName, HttpServletRequest request) { |
| 235 | + Integer size = captchaMap.get(request.getSession().getId()); | ||
| 231 | return size == null ? 0 : size; | 236 | return size == null ? 0 : size; |
| 232 | } | 237 | } |
| 233 | 238 |