BUGFIX:用户注册后重发验证码,验证不通过

This commit is contained in:
2025-06-24 19:30:20 +08:00
parent d6c5d0e95d
commit 13514b277b
3 changed files with 16 additions and 7 deletions

View File

@@ -31,7 +31,9 @@ public enum AuthenticationOperationTypeEnum {
/**
* 填写用户国家和职业
*/
UPDATE_USERINFO;
UPDATE_USERINFO,
REGISTER;
public static AuthenticationOperationTypeEnum of(String name) {
return Stream.of(AuthenticationOperationTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null);

View File

@@ -15,8 +15,8 @@ public class EmailSendDTO {
private String email;
@NotBlank(message = "operationType.cannot.be.empty")
@ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱 " +
"CHANGE_MAILBOX 更改邮箱 UPDATE_USERINFO 仅填写国家、职业(不发送邮件)")
@ApiModelProperty("操作类型 LOGIN 登录 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱 " +
"CHANGE_MAILBOX 更改邮箱 UPDATE_USERINFO 仅填写国家、职业(不发送邮件) REGISTER 注册")
private String operationType;
@ApiModelProperty("异常ip")

View File

@@ -517,11 +517,15 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
result = true;
}
break;
case REGISTER:
result = SendEmailUtil.designWorksRegister(emailSendDTO.getEmail(), randomVerifyCode);
break;
default:
}
if (!result) {
throw new BusinessException("failed.to.send.mail");
}
log.info("向邮箱 {} 发送验证码为:{}, 邮件类型:{}", emailSendDTO.getEmail(), randomVerifyCode, authenticationOperationTypeEnum);
return Boolean.TRUE;
}
@@ -1287,27 +1291,30 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
@Override
public Boolean designWorksRegister(AccountDesignWorksRegisterDTO accountDesignWorksRegisterDTO) {
String userEmail = accountDesignWorksRegisterDTO.getUserEmail();
log.info("账号注册,邮箱为:{}", userEmail);
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.eq("BINARY user_email", accountDesignWorksRegisterDTO.getUserEmail());
qw.eq("BINARY user_email", userEmail);
List<Account> accountList = accountMapper.selectList(qw);
if (CollectionUtil.isNotEmpty(accountList)) {
throw new BusinessException("The email has already been registered");
}
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache("DesignWorksRegister" + "_" + accountDesignWorksRegisterDTO.getUserEmail(), randomVerifyCode);
LocalCacheUtils.setVerifyCodeCache("REGISTER" + "_" + userEmail, randomVerifyCode);
Boolean b = SendEmailUtil.designWorksRegister(accountDesignWorksRegisterDTO.getUserEmail(), randomVerifyCode);
Boolean b = SendEmailUtil.designWorksRegister(userEmail, randomVerifyCode);
if (!b) {
throw new BusinessException("failed.to.send.mail");
}
log.info("向邮箱 {} 发送验证码:{}, 邮件类型REGISTER", userEmail, randomVerifyCode);
return Boolean.TRUE;
}
@Override
public AccountLoginVO designWorksRegisterCode(AccountDesignWorksRegisterDTO accountDesignWorksRegisterDTO) {
String verifyCode = LocalCacheUtils.getVerifyCodeCache("DesignWorksRegister" + "_" + accountDesignWorksRegisterDTO.getUserEmail());
String verifyCode = LocalCacheUtils.getVerifyCodeCache("REGISTER" + "_" + accountDesignWorksRegisterDTO.getUserEmail());
if (StringUtils.isBlank(verifyCode)) {
throw new BusinessException("the.verification.code.has.expired", ResultEnum.PROMPT.getCode());
}