Search in sources :

Example 1 with EmailCodeVo

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);
    }
}
Also used : ResultVO(shu.java.csky.vo.ResultVO) EmailCodeVo(shu.java.csky.vo.EmailCodeVo) EmailCode(shu.java.csky.entity.EmailCode) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)1 EmailCode (shu.java.csky.entity.EmailCode)1 EmailCodeVo (shu.java.csky.vo.EmailCodeVo)1 ResultVO (shu.java.csky.vo.ResultVO)1