Search in sources :

Example 1 with MailInfo

use of com.fanxb.bookmark.common.entity.MailInfo in project bookmark by FleyX.

the class BaseInfoServiceImpl method updateEmail.

@Override
@Transactional(rollbackFor = Exception.class)
public void updateEmail(EmailUpdateBody body) {
    int userId = UserContextHolder.get().getUserId();
    String oldPassword = userDao.selectByUserIdOrGithubId(userId, null).getPassword();
    if (!StrUtil.equals(oldPassword, HashUtil.getPassword(body.getOldPassword()))) {
        throw new CustomException("密码校验失败,无法更新email");
    }
    String secret = UUID.randomUUID().toString().replaceAll("-", "");
    String url = VERIFY_EMAIL.replaceAll("XXXX", CommonConstant.serviceAddress + VERIFY_EMAIL_PATH + secret);
    log.debug(url);
    MailInfo info = new MailInfo(body.getEmail(), "验证邮箱", url);
    MailUtil.sendMail(info, true);
    RedisUtil.set(RedisConstant.getUpdateEmailKey(secret), String.valueOf(userId), TimeUtil.DAY_MS);
    userDao.updateNewEmailByUserId(userId, body.getEmail());
}
Also used : CustomException(com.fanxb.bookmark.common.exception.CustomException) MailInfo(com.fanxb.bookmark.common.entity.MailInfo) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MailInfo

use of com.fanxb.bookmark.common.entity.MailInfo in project bookmark by FleyX.

the class UserServiceImpl method sendAuthCode.

/**
 * Description: 向目标发送验证码
 *
 * @param email 目标
 * @author fanxb
 * @date 2019/7/5 17:48
 */
public void sendAuthCode(String email) {
    MailInfo info = new MailInfo();
    info.setSubject("签签世界注册验证码");
    String code = StringUtil.getRandomString(6, 2);
    info.setContent("欢迎注册 签签世界 ,本次验证码");
    info.setContent(code + " 是您的验证码,注意验证码有效期为15分钟哦!");
    info.setReceiver(email);
    if (CommonConstant.isDev) {
        code = "123456";
    } else {
        MailUtil.sendTextMail(info);
    }
    RedisUtil.set(CommonConstant.authCodeKey(email), code, CommonConstant.AUTH_CODE_EXPIRE);
}
Also used : MailInfo(com.fanxb.bookmark.common.entity.MailInfo)

Aggregations

MailInfo (com.fanxb.bookmark.common.entity.MailInfo)2 CustomException (com.fanxb.bookmark.common.exception.CustomException)1 Transactional (org.springframework.transaction.annotation.Transactional)1