use of shu.java.csky.vo.EmailCodeVo in project CSKY by SHU-Silence.
the class EmailCodeServiceImpl method sendCode.
/**
* 1. 已经注册过的不能再注册
* 2. 验证码的时效问题
*
* @param email
* @return
*/
@Override
public ResultVO sendCode(String email) {
EmailCode emailCode = new EmailCode();
emailCode.setCode(createCode());
emailCode.setEmail(email);
try {
MailUtil.sendCode(email, emailCode.getCode(), "计算机考研网邮箱验证码");
} catch (Exception e) {
throw new RuntimeException("邮箱验证码发送失败!");
}
try {
emailCodeMapper.insert(emailCode);
QueryWrapper<EmailCode> wrapper = new QueryWrapper<>();
wrapper.eq("code", emailCode.getCode());
EmailCode emailCode1 = emailCodeMapper.selectOne(wrapper);
EmailCodeVo emailCodeVo = new EmailCodeVo();
BeanUtils.copyProperties(emailCode1, emailCodeVo);
return new ResultVO(ResStatus.OK, "验证码发送成功!", emailCodeVo);
} catch (Exception e) {
e.printStackTrace();
return new ResultVO(ResStatus.NO, "验证码发送失败!", null);
}
}
Aggregations