feat: register logic refactor

This commit is contained in:
merlin
2025-11-17 18:02:58 +08:00
parent 575041905b
commit 23cb31d4fe
45 changed files with 768 additions and 70 deletions

View File

@@ -0,0 +1,36 @@
package xin.merlin.myplayerbackend.service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class MailService {
private final JavaMailSender mailSender;
@Value("${spring.mail.username}")
private String mail;
public String sendMail(String receiver){
try {
String code = Double.toString(Math.random()).substring(2,8);
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(mail);
message.setTo(receiver);
message.setSubject("Welcome to use Merlin`s product");
message.setText("欢迎使用Merlin.xin产品 \n"+"您的验证码为:"+code+"\n有效期五分钟请勿泄露");
mailSender.send(message);
return code;
} catch (MailException e) {
log.error("e: ", e);
throw new RuntimeException(e);
}
}
}