From 64cc29f456d6e04c28e27ebd9017b2d58f786eae Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 21 Jan 2026 14:13:33 +0800 Subject: [PATCH] =?UTF-8?q?TASK:Global=20Award=E9=82=AE=E7=AE=B1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/controller/GlobalAwardController.java | 4 +- .../com/ai/da/service/GlobalAwardService.java | 2 +- .../service/impl/GlobalAwardServiceImpl.java | 43 ++++++++++++++----- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/ai/da/controller/GlobalAwardController.java b/src/main/java/com/ai/da/controller/GlobalAwardController.java index 2d461410..a7cb54d1 100644 --- a/src/main/java/com/ai/da/controller/GlobalAwardController.java +++ b/src/main/java/com/ai/da/controller/GlobalAwardController.java @@ -47,8 +47,8 @@ public class GlobalAwardController { } @GetMapping("/checkCode") - public Response checkOTP(@RequestParam("email") String email, @RequestParam("code") String code) { - return Response.success(globalAwardService.checkOTP(email, code)); + public Response checkCode(@RequestParam("email") String email, @RequestParam("code") String code) { + return Response.success(globalAwardService.checkCode(email, code)); } } diff --git a/src/main/java/com/ai/da/service/GlobalAwardService.java b/src/main/java/com/ai/da/service/GlobalAwardService.java index 3b66579c..48396e22 100644 --- a/src/main/java/com/ai/da/service/GlobalAwardService.java +++ b/src/main/java/com/ai/da/service/GlobalAwardService.java @@ -17,7 +17,7 @@ public interface GlobalAwardService { void checkEmail(String email); - CheckOTPVO checkOTP(String email, String otp); + CheckOTPVO checkCode(String email, String otp); } diff --git a/src/main/java/com/ai/da/service/impl/GlobalAwardServiceImpl.java b/src/main/java/com/ai/da/service/impl/GlobalAwardServiceImpl.java index 033817a7..3d3d17b5 100644 --- a/src/main/java/com/ai/da/service/impl/GlobalAwardServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GlobalAwardServiceImpl.java @@ -134,13 +134,7 @@ public class GlobalAwardServiceImpl implements GlobalAwardService { throw new IllegalArgumentException("email required"); } - String key = tokenCacheKey + request.getEmail(); - String tokenCache = redisUtil.getFromString(key); - if (StringUtils.isBlank(tokenCache)) { - throw new BusinessException("请先完成邮箱认证"); - } else if (!tokenCache.equals(request.getSecureToken())){ - throw new BusinessException("身份认证失败,请先完成邮箱认证"); - } + checkSecurityToken(request.getEmail(), request.getSecureToken()); QueryWrapper qw = new QueryWrapper<>(); qw.eq("email", request.getEmail()); @@ -217,6 +211,10 @@ public class GlobalAwardServiceImpl implements GlobalAwardService { return dto; } + /** + * 检查邮箱是否符合申请要求,发送验证码 + * @param email AiDA邮箱 + */ public void checkEmail(String email) { List validRole = Arrays.asList(1, 2, 7, 8); // 1. 验证邮箱在aida中有无账号 @@ -224,7 +222,7 @@ public class GlobalAwardServiceImpl implements GlobalAwardService { queryWrapper.lambda().eq(Account::getUserEmail, email); List accounts = accountMapper.selectList(queryWrapper); if (accounts.isEmpty()) { - throw new BusinessException("请注册并订阅AiDA,再重新提交申请"); + throw new BusinessException("Please register and subscribe to AiDA, then resubmit your application."); } // 2. 验证账号是否是付费用户(如果首次提交是,但是修改的时候已经不是了,how?不允许修改吗) @@ -235,11 +233,17 @@ public class GlobalAwardServiceImpl implements GlobalAwardService { SendEmailUtil.send(email, null, SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode); } else { - throw new BusinessException("请订阅AiDA,再重新提交申请"); + throw new BusinessException("Please subscribe to AiDA, then resubmit your application."); } } - public CheckOTPVO checkOTP(String email, String otp) { + /** + * 验证验证码是否正确 + * @param email 邮箱 + * @param otp 一次性验证码 + * @return 临时token和之前提交的表单内容 + */ + public CheckOTPVO checkCode(String email, String otp) { String otpCache = LocalCacheUtils.getVerifyCodeCache(AuthenticationOperationTypeEnum.GLOBAL_AWARD.name() + "_" + email); assert otpCache != null; if (otpCache.equals(otp)) { @@ -249,7 +253,24 @@ public class GlobalAwardServiceImpl implements GlobalAwardService { return new CheckOTPVO(secureToken, getContestantByEmail(email)); } else { - throw new BusinessException("验证码错误,请重试"); + throw new BusinessException("Verification code is incorrect. Please try again."); + } + } + + public void checkSecurityToken(String email, String securityToken) { + String key = tokenCacheKey + email; + if (StringUtils.isBlank(securityToken)) { + log.error("security token 缺失"); + throw new BusinessException("Please complete email verification first."); + } + + String tokenCache = redisUtil.getFromString(key); + if (StringUtils.isBlank(tokenCache)) { + log.error("security token 过期"); + throw new BusinessException("Email verification has expired. Please verify again."); + } else if (!tokenCache.equals(securityToken)){ + log.error("security token 与缓存不符"); + throw new BusinessException("Identity verification failed. Please complete email verification first."); } }