From e573286f0a0eb3dc8244b10646940bcdc08940b8 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Tue, 6 Jul 2021 15:09:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.0.4=E3=80=91=E3=80=90c=E3=80=91?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=92=8C=E5=8F=91=E9=80=81=E9=82=AE=E7=AE=B1?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E5=8A=A0=E4=B8=8A=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modular/request/CustomerRequest.java | 10 ++++++ .../service/impl/CustomerServiceImpl.java | 36 +++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/request/CustomerRequest.java b/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/request/CustomerRequest.java index 6fed4dcfa..5009ffa39 100644 --- a/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/request/CustomerRequest.java +++ b/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/request/CustomerRequest.java @@ -98,6 +98,16 @@ public class CustomerRequest extends BaseRequest { @ChineseDescription("用户状态:1-启用,2-禁用") private Integer statusFlag; + /** + * 用在图形验证码或者拖拽验证码 + */ + private String verKey; + + /** + * 用在图形验证码或者拖拽验证码 + */ + private String verCode; + /** * 注册账号 */ diff --git a/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/service/impl/CustomerServiceImpl.java b/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/service/impl/CustomerServiceImpl.java index 049334012..323c360ce 100644 --- a/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/service/impl/CustomerServiceImpl.java +++ b/kernel-s-customer/customer-business/src/main/java/cn/stylefeng/roses/kernel/customer/modular/service/impl/CustomerServiceImpl.java @@ -102,6 +102,10 @@ public class CustomerServiceImpl extends ServiceImpl i @Override @Transactional(rollbackFor = Exception.class) public void reg(CustomerRequest customerRequest) { + + // 验证拖拽验证码 + this.validateDragCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode()); + synchronized (REG_LOCK) { // 校验邮箱和账号是否重复 validateRepeat(customerRequest); @@ -143,17 +147,7 @@ public class CustomerServiceImpl extends ServiceImpl i loginRequest.setRememberMe(true); // 验证拖拽验证码 - if (SecurityConfigExpander.getDragCaptchaOpen()) { - 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); - } - } + this.validateDragCaptcha(loginRequest.getVerKey(), loginRequest.getVerCode()); // 查询用户信息 LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); @@ -217,6 +211,9 @@ public class CustomerServiceImpl extends ServiceImpl i @Transactional(rollbackFor = Exception.class) public void sendResetPwdEmail(CustomerRequest customerRequest) { + // 验证拖拽验证码 + this.validateDragCaptcha(customerRequest.getVerKey(), customerRequest.getVerCode()); + // 验证邮箱是否存在 LambdaQueryWrapper customerLambdaQueryWrapper = new LambdaQueryWrapper<>(); customerLambdaQueryWrapper.eq(Customer::getEmail, customerRequest.getEmail()); @@ -446,5 +443,22 @@ public class CustomerServiceImpl extends ServiceImpl 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); + } + } + } + } \ No newline at end of file