整合预先登录接口与邮件发送
This commit is contained in:
@@ -14,7 +14,19 @@ public class AccountPreLoginDTO {
|
||||
@ApiModelProperty("用户名")
|
||||
private String userName;
|
||||
|
||||
/*新增字段*/
|
||||
@NotBlank(message = "Please input email !")
|
||||
@ApiModelProperty("邮箱")
|
||||
private String email;
|
||||
|
||||
@NotBlank(message = "password cannot be empty!")
|
||||
@ApiModelProperty("密码")
|
||||
private String password;
|
||||
|
||||
@NotBlank(message = "operationType cannot be empty")
|
||||
@ApiModelProperty("操作类型 LOGIN 注册 FORGET_PWD 忘记密码 BIND_MAILBOX 绑定邮箱")
|
||||
private String operationType;
|
||||
|
||||
@ApiModelProperty("异常ip")
|
||||
private String ip;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user