整合预先登录接口与邮件发送

This commit is contained in:
zhouchengrong
2023-07-20 14:18:50 +08:00
parent 7e9fdca250
commit 60ae1e3849
46 changed files with 55 additions and 12 deletions

View File

@@ -73,6 +73,37 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
}else{
Assert.isTrue(account.getUserPassword().equals(accountDTO.getPassword()),"Password error !");
}
/*发送邮件*/
OperationTypeEnum operationTypeEnum = OperationTypeEnum.of(accountDTO.getOperationType());
Assert.notNull(operationTypeEnum, "Unknown operation type!");
String randomVerifyCode = RandomsUtil.generateVerifyCode(100000L, 999999L);
LocalCacheUtils.setVerifyCodeCache(
accountDTO.getOperationType() + "_" + accountDTO.getEmail(), randomVerifyCode);
Boolean result = Boolean.FALSE;
switch (operationTypeEnum) {
case LOGIN:
Assert.notNull(accountDTO, "Email not registered!");
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.LOGIN_TEMPLATE_ID, randomVerifyCode);
break;
case FORGET_PWD:
Assert.notNull(accountDTO, "Email not registered!");
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.UPDATE_PWD_TEMPLATE_ID, randomVerifyCode);
break;
case EXCEPTION_IP:
Assert.notNull(accountDTO, "Email not registered!");
result = SendEmailUtil.send(accountDTO.getEmail(), accountDTO.getIp(),
SendEmailUtil.EXCEPTION_ID_TEMPLATE_ID, randomVerifyCode);
break;
case BIND_MAILBOX:
result = SendEmailUtil.send(accountDTO.getEmail(), null,
SendEmailUtil.BIND_MAILBOX_TEMPLATE_ID, randomVerifyCode);
break;
default:
Assert.notNull(operationTypeEnum, "Unknown operation type!");
}
Assert.isTrue(result, "Failed to send mail");
return new AccountPreLoginVO(account.getId());
}