增加忘记密码功能完善(邮件内容)

pull/2/head
陈映江 5 months ago
parent 2c28c23b14
commit 3a306a6c35

@ -1,8 +1,8 @@
[ {
"username" : "小鱼",
"email" : "1280556515@qq.com",
"passwordHash" : "$2a$12$0.CsIN83oxG1vbZe6vNVte3JaxvX2JU2j0hyprng6meq9/N4e732m",
"passwordHash" : "$2a$12$fAWGM2CJSSiulyFbDWyRyefrBWr9emYrMdkD.Rw2LPKFaYQeYYW9K",
"registrationDate" : [ 2025, 10, 8, 21, 0, 37, 863490500 ],
"verificationCode" : "963213",
"verificationCode" : "926911",
"verified" : true
} ]

@ -19,7 +19,7 @@ public class EmailService {
this.auth = auth;
}
public boolean sendVerificationCode(String toEmail, String verificationCode) {
public boolean sendVerificationCode(String toEmail, String verificationCode, int flag) {
try {
Properties props = new Properties();
props.put("mail.smtp.host", host);
@ -38,12 +38,11 @@ public class EmailService {
message.setFrom(new InternetAddress(username));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail));
message.setSubject("数学学习软件 - 注册验证码");
String emailContent="";
if (flag == 1) emailContent = registerContent(verificationCode);
else if (flag == 2) emailContent = resetPasswordContent(verificationCode);
String emailContent = "尊敬的用户:\n\n" +
"您的注册验证码是:" + verificationCode + "\n\n" +
"该验证码有效期为10分钟。\n\n" +
"如果您没有注册本软件,请忽略此邮件。\n\n" +
"数学学习软件团队";
message.setText(emailContent);
@ -54,4 +53,20 @@ public class EmailService {
return false;
}
}
public String registerContent(String verificationCode) {
return "尊敬的用户:\n\n" +
"您的注册验证码是:" + verificationCode + "\n\n" +
"该验证码有效期为10分钟。\n\n" +
"如果您没有注册本软件,请忽略此邮件。\n\n" +
"数学学习软件团队";
}
public String resetPasswordContent(String verificationCode) {
return "尊敬的用户:\n\n" +
"您的重置验证码是:" + verificationCode + "\n\n" +
"该验证码有效期为10分钟。\n\n" +
"如果您没有重置密码,请忽略此邮件。\n\n" +
"数学学习软件团队";
}
}

@ -139,7 +139,7 @@ public class ChangeCodeFrame extends JFrame {
verificationCode = String.valueOf((int)((Math.random() * 9 + 1) * 100000));
// 发送验证码邮件
boolean sent = emailService.sendVerificationCode(email, verificationCode);
boolean sent = emailService.sendVerificationCode(email, verificationCode, 2);
if (sent) {
// 在服务中保存验证码

@ -145,7 +145,7 @@ public class RegisterFrame extends JFrame{
verificationCode = String.valueOf((int)((Math.random() * 9 + 1) * 100000));
// 发送验证码邮件
boolean sent = emailService.sendVerificationCode(email, verificationCode);
boolean sent = emailService.sendVerificationCode(email, verificationCode, 1);
if (sent) {
JOptionPane.showMessageDialog(RegisterFrame.this,

Loading…
Cancel
Save