【7.0.4】【c】注册和发送邮箱验证码加上安全校验

pull/22/head
fengshuonan 2021-07-06 15:09:11 +08:00
parent fe3e180ed0
commit e573286f0a
2 changed files with 35 additions and 11 deletions

View File

@ -98,6 +98,16 @@ public class CustomerRequest extends BaseRequest {
@ChineseDescription("用户状态1-启用2-禁用") @ChineseDescription("用户状态1-启用2-禁用")
private Integer statusFlag; private Integer statusFlag;
/**
*
*/
private String verKey;
/**
*
*/
private String verCode;
/** /**
* *
*/ */

View File

@ -102,6 +102,10 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void reg(CustomerRequest customerRequest) { public void reg(CustomerRequest customerRequest) {
// 验证拖拽验证码
this.validateDragCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode());
synchronized (REG_LOCK) { synchronized (REG_LOCK) {
// 校验邮箱和账号是否重复 // 校验邮箱和账号是否重复
validateRepeat(customerRequest); validateRepeat(customerRequest);
@ -143,17 +147,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
loginRequest.setRememberMe(true); loginRequest.setRememberMe(true);
// 验证拖拽验证码 // 验证拖拽验证码
if (SecurityConfigExpander.getDragCaptchaOpen()) { this.validateDragCaptcha(loginRequest.getVerKey(), loginRequest.getVerCode());
String verKey = loginRequest.getVerKey();
String verXLocationValue = loginRequest.getVerCode();
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verXLocationValue)) {
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
}
if (!dragCaptchaApi.validateCaptcha(verKey, Convert.toInt(verXLocationValue))) {
throw new AuthException(ValidatorExceptionEnum.DRAG_CAPTCHA_ERROR);
}
}
// 查询用户信息 // 查询用户信息
LambdaQueryWrapper<Customer> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Customer> wrapper = new LambdaQueryWrapper<>();
@ -217,6 +211,9 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void sendResetPwdEmail(CustomerRequest customerRequest) { public void sendResetPwdEmail(CustomerRequest customerRequest) {
// 验证拖拽验证码
this.validateDragCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode());
// 验证邮箱是否存在 // 验证邮箱是否存在
LambdaQueryWrapper<Customer> customerLambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Customer> customerLambdaQueryWrapper = new LambdaQueryWrapper<>();
customerLambdaQueryWrapper.eq(Customer::getEmail, customerRequest.getEmail()); customerLambdaQueryWrapper.eq(Customer::getEmail, customerRequest.getEmail());
@ -446,5 +443,22 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
} }
} }
/**
*
*
* @author fengshuonan
* @date 2021/7/6 15:07
*/
private void validateDragCaptcha(String verKey, String verCode) {
if (SecurityConfigExpander.getDragCaptchaOpen()) {
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verCode)) {
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
}
if (!dragCaptchaApi.validateCaptcha(verKey, Convert.toInt(verCode))) {
throw new AuthException(ValidatorExceptionEnum.DRAG_CAPTCHA_ERROR);
}
}
}
} }