@@ -134,13 +134,7 @@ public class GlobalAwardServiceImpl implements GlobalAwardService {
throw new BusinessException ( " Email is 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 < Contestant > 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 < Integer > 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 < Account > 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. " ) ;
}
}