Commit 9081d3a2 authored by 技术部-任文超's avatar 技术部-任文超

添加Log

parent 71ac09e0
...@@ -89,6 +89,7 @@ public class CaptchaFiniteValidateAdvisor { ...@@ -89,6 +89,7 @@ public class CaptchaFiniteValidateAdvisor {
String phoneNo = phonePasswordMap.get("phoneNo"); String phoneNo = phonePasswordMap.get("phoneNo");
Long countErrorByPhone = getCount(phoneNo); Long countErrorByPhone = getCount(phoneNo);
if(countErrorByPhone == null){ if(countErrorByPhone == null){
LOGGER.info("用户名或密码不正确, phoneNo={}, countErrorByPhone={}, clientIp={}", phoneNo, countErrorByPhone, request.getRemoteAddr());
return JsonResult.buildErrorStateResult("用户名或密码不正确", null); return JsonResult.buildErrorStateResult("用户名或密码不正确", null);
} }
if (countErrorByPhone > Constants.Image_Need_Count) { if (countErrorByPhone > Constants.Image_Need_Count) {
......
...@@ -42,6 +42,7 @@ public class ExceptionHandlingController implements IBaseController { ...@@ -42,6 +42,7 @@ public class ExceptionHandlingController implements IBaseController {
*/ */
@ExceptionHandler(PasswordErrorLimitException.class) @ExceptionHandler(PasswordErrorLimitException.class)
public JsonResult passwordErrorLimitException(PasswordErrorLimitException vce) { public JsonResult passwordErrorLimitException(PasswordErrorLimitException vce) {
LOGGER.info("throw PasswordErrorLimitException,msg={},businessCode={}", vce.getMessage(), 2L);
return JsonResult.buildErrorStateResult(vce.getMessage(), null, 2L); return JsonResult.buildErrorStateResult(vce.getMessage(), null, 2L);
} }
...@@ -53,12 +54,14 @@ public class ExceptionHandlingController implements IBaseController { ...@@ -53,12 +54,14 @@ public class ExceptionHandlingController implements IBaseController {
*/ */
@ExceptionHandler(VerificationCodeErrorException.class) @ExceptionHandler(VerificationCodeErrorException.class)
public JsonResult verificationCodeErrorException(VerificationCodeErrorException vce) { public JsonResult verificationCodeErrorException(VerificationCodeErrorException vce) {
LOGGER.info("throw VerificationCodeErrorException,msg={},businessCode={}", vce.getMessage(), 1L);
return JsonResult.buildErrorStateResult(vce.getMessage(), null, 1L); return JsonResult.buildErrorStateResult(vce.getMessage(), null, 1L);
} }
@ExceptionHandler(UserNotExistException.class) @ExceptionHandler(UserNotExistException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED) @ResponseStatus(HttpStatus.UNAUTHORIZED)
public JsonResult userNotExistException(UserNotExistException unee) { public JsonResult userNotExistException(UserNotExistException unee) {
LOGGER.info("throw UserNotExistException,msg={},businessCode={},code={}", unee.getMessage(), 1L, 401L);
return new JsonResult(unee.getMessage(), 401L, null); return new JsonResult(unee.getMessage(), 401L, null);
} }
......
...@@ -531,8 +531,10 @@ public class UserController implements IBaseController { ...@@ -531,8 +531,10 @@ public class UserController implements IBaseController {
} }
String[] credentialArr = bufStr.split(":"); String[] credentialArr = bufStr.split(":");
if (credentialArr.length != 2) { if (credentialArr.length != 2) {
LOGGER.info("用户登录失败:{}", bufStr);
return null; return null;
} }
LOGGER.info("用户正在登录... [{}]", credentialArr);
String userName = credentialArr[0]; String userName = credentialArr[0];
String pass = credentialArr[1]; String pass = credentialArr[1];
User user = userService.findByPhoneWithCache(userName); User user = userService.findByPhoneWithCache(userName);
...@@ -541,8 +543,19 @@ public class UserController implements IBaseController { ...@@ -541,8 +543,19 @@ public class UserController implements IBaseController {
} }
//验证密码 //验证密码
if (!validatePassword(pass, user.getPassword())) { if (!validatePassword(pass, user.getPassword())) {
doErrorCount(userName);
return null;
}
return user;
}
/**
* 执行账密登录错误计数
* @param phoneNo
*/
private void doErrorCount(String phoneNo) {
// 密码错误时,给该账号添加计数器 // 密码错误时,给该账号添加计数器
String key = Constants.REDIS_PASSWORD_ERROR_COUNT + userName; String key = Constants.REDIS_PASSWORD_ERROR_COUNT + phoneNo;
if (!stringRedisTemplate.hasKey(key)) { if (!stringRedisTemplate.hasKey(key)) {
stringRedisTemplate.opsForValue().set(key, String.valueOf(0), DateUtils.getSeconds(), TimeUnit.SECONDS); stringRedisTemplate.opsForValue().set(key, String.valueOf(0), DateUtils.getSeconds(), TimeUnit.SECONDS);
} }
...@@ -553,9 +566,6 @@ public class UserController implements IBaseController { ...@@ -553,9 +566,6 @@ public class UserController implements IBaseController {
}else if(Objects.equals(errorCount, Constants.Image_Need_Count)){ }else if(Objects.equals(errorCount, Constants.Image_Need_Count)){
throw new PasswordErrorLimitException("请输入图形验证码"); throw new PasswordErrorLimitException("请输入图形验证码");
} }
return null;
}
return user;
} }
private boolean validatePassword(String paramPass, String targetPassword) { private boolean validatePassword(String paramPass, String targetPassword) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment