mirror of https://gitee.com/stylefeng/roses
【7.1.6】【customer】c端用户增加图形验证码
parent
da629d3747
commit
2dbcd912a2
|
@ -45,6 +45,7 @@ import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||||
import cn.stylefeng.roses.kernel.rule.exception.enums.defaults.DefaultBusinessExceptionEnum;
|
import cn.stylefeng.roses.kernel.rule.exception.enums.defaults.DefaultBusinessExceptionEnum;
|
||||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||||
import cn.stylefeng.roses.kernel.security.api.DragCaptchaApi;
|
import cn.stylefeng.roses.kernel.security.api.DragCaptchaApi;
|
||||||
|
import cn.stylefeng.roses.kernel.security.api.ImageCaptchaApi;
|
||||||
import cn.stylefeng.roses.kernel.security.api.expander.SecurityConfigExpander;
|
import cn.stylefeng.roses.kernel.security.api.expander.SecurityConfigExpander;
|
||||||
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
|
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
@ -106,12 +107,15 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
@Resource
|
@Resource
|
||||||
private OldPasswordValidateApi oldPasswordValidateApi;
|
private OldPasswordValidateApi oldPasswordValidateApi;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ImageCaptchaApi imageCaptchaApi;
|
||||||
|
|
||||||
@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());
|
this.validateCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode());
|
||||||
|
|
||||||
synchronized (REG_LOCK) {
|
synchronized (REG_LOCK) {
|
||||||
// 校验邮箱和账号是否重复
|
// 校验邮箱和账号是否重复
|
||||||
|
@ -154,7 +158,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
loginRequest.setRememberMe(true);
|
loginRequest.setRememberMe(true);
|
||||||
|
|
||||||
// 验证拖拽验证码
|
// 验证拖拽验证码
|
||||||
this.validateDragCaptcha(loginRequest.getVerKey(), loginRequest.getVerCode());
|
this.validateCaptcha(loginRequest.getVerKey(), loginRequest.getVerCode());
|
||||||
|
|
||||||
// 查询用户信息
|
// 查询用户信息
|
||||||
LambdaQueryWrapper<Customer> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Customer> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
@ -228,7 +232,7 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
public void sendResetPwdEmail(CustomerRequest customerRequest) {
|
public void sendResetPwdEmail(CustomerRequest customerRequest) {
|
||||||
|
|
||||||
// 验证拖拽验证码
|
// 验证拖拽验证码
|
||||||
this.validateDragCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode());
|
this.validateCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode());
|
||||||
|
|
||||||
// 验证邮箱是否存在
|
// 验证邮箱是否存在
|
||||||
LambdaQueryWrapper<Customer> customerLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Customer> customerLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
@ -557,12 +561,25 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证拖拽验证码是否正确
|
* 验证码是否正确
|
||||||
*
|
*
|
||||||
* @author fengshuonan
|
* @author fengshuonan
|
||||||
* @date 2021/7/6 15:07
|
* @date 2021/7/6 15:07
|
||||||
*/
|
*/
|
||||||
private void validateDragCaptcha(String verKey, String verCode) {
|
private void validateCaptcha(String verKey, String verCode) {
|
||||||
|
|
||||||
|
// 如果开启了验证码校验,则验证当前请求的验证码是否正确
|
||||||
|
if (SecurityConfigExpander.getCaptchaOpen()) {
|
||||||
|
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verCode)) {
|
||||||
|
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||||
|
}
|
||||||
|
if (!imageCaptchaApi.validateCaptcha(verKey, verCode)) {
|
||||||
|
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_ERROR);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果开启了拖拽验证码
|
||||||
if (SecurityConfigExpander.getDragCaptchaOpen()) {
|
if (SecurityConfigExpander.getDragCaptchaOpen()) {
|
||||||
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verCode)) {
|
if (StrUtil.isEmpty(verKey) || StrUtil.isEmpty(verCode)) {
|
||||||
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||||
|
@ -573,5 +590,4 @@ public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue