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

优化提示文案

parent ac0d24e8
......@@ -94,16 +94,14 @@ public class CaptchaFiniteValidateAdvisor {
if (countErrorByPhone > Constants.Image_Need_Count) {
String registerFrom = Optional.ofNullable(request.getParameter("registerFrom")).orElse("");
String captchaId = Optional.ofNullable(request.getParameter("captchaId")).orElse("");
Object captchaValue = request.getParameter("captchaValue");
String deviceId = Optional.ofNullable(request.getParameter("deviceId")).orElse("");
String captchaValue = request.getParameter("captchaValue");
if (shouldSkipCaptchaValidate(registerFrom, captchaId, captchaValue)) {
LOGGER.info("使用超级图形验证码校验, registerFrom={}, clientIp={}", registerFrom, request.getRemoteAddr());
return pjp.proceed();
}
if (captchaValue != null) {
String captcha = String.valueOf(captchaValue);
if (StringUtils.isNotBlank(captchaValue)) {
// 忽略用户输入的大小写
captcha = StringUtils.lowerCase(captcha);
String captcha = StringUtils.lowerCase(captchaValue);
// 验证码校验
Boolean validCaptcha = false;
try {
......
......@@ -83,7 +83,7 @@ public class CaptchaNewValidateAdvisor {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String registerFrom = Optional.ofNullable(request.getParameter("registerFrom")).orElse("");
String captchaId = Optional.ofNullable(request.getParameter("captchaId")).orElse("");
Object captchaValue = request.getParameter("captchaValue");
String captchaValue = request.getParameter("captchaValue");
String phoneNo = request.getParameter("phoneNo");
String deviceId = Optional.ofNullable(request.getParameter("deviceId")).orElse("");
String clientIp = getIp();
......@@ -100,10 +100,9 @@ public class CaptchaNewValidateAdvisor {
JsonResult result = JsonResult.buildSuccessResult("图形验证码不正确", "");
result.setBusinessCode("0002");
if (captchaValue != null && StringUtils.isNotEmpty(String.valueOf(captchaValue))) {
String captcha = String.valueOf(captchaValue);
if (StringUtils.isNotBlank(captchaValue)) {
// 忽略用户输入的大小写
captcha = StringUtils.lowerCase(captcha);
String captcha = StringUtils.lowerCase(captchaValue);
// 验证码校验
Boolean validCaptcha = false;
try {
......@@ -111,7 +110,6 @@ public class CaptchaNewValidateAdvisor {
} catch (CaptchaServiceException ex) {
LOGGER.error("验证码校验异常, {}, {}", ex.getMessage(), ex);
}
if (validCaptcha) {
return pjp.proceed();
}
......@@ -119,19 +117,15 @@ public class CaptchaNewValidateAdvisor {
}
result.setMsg("请输入图形验证码");
return result;
}
return pjp.proceed();
}
private boolean shouldSkipCaptchaValidate(String registerFrom, String captchaId, Object captchaValue) {
// 如果启用了超级验证码功能, 检查超级验证码, 超级验证码区分大小写
if (autoTestCaptchaEnabled) {
return true;
}
return StringUtils.equals(SUPER_CAPTCHA_ID, String.valueOf(captchaId)) && StringUtils.equals(SUPER_CAPTCHA, String.valueOf(captchaValue));
}
......@@ -190,30 +184,25 @@ public class CaptchaNewValidateAdvisor {
private String getIp() {
HttpServletRequest request = getRequest();
String ip = request.getHeader("x-real-ip");
if (StringUtils.isEmpty(ip)) {
ip = request.getRemoteAddr();
}
//过滤反向代理的ip
String[] stemps = ip.split(",");
if (stemps.length >= 1) {
//得到第一个IP,即客户端真实IP
ip = stemps[0];
}
ip = ip.trim();
if (ip.length() > 23) {
ip = ip.substring(0, 23);
}
return ip;
}
private HttpServletRequest getRequest() {
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
return attrs.getRequest();
}
}
......@@ -41,6 +41,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.TimeUnit;
......@@ -545,6 +546,8 @@ public class UserController implements IBaseController {
// 密码错误计数
Long errorCount = stringRedisTemplate.opsForValue().increment(key, 1L);
if(errorCount > Constants.Image_Need_Count){
throw new PasswordErrorLimitException("用户名或密码不正确");
}else if(Objects.equals(errorCount, Constants.Image_Need_Count)){
throw new PasswordErrorLimitException("请输入图形验证码");
}
return null;
......@@ -646,7 +649,7 @@ public class UserController implements IBaseController {
private boolean needRetSendCode(String phoneNo) {
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
Long getVerificationCount = stringRedisTemplate.opsForHash().increment(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT, 1);
return (getVerificationCount > 5);
return (getVerificationCount >= 5);
}
}
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