refactor(email): 优化邮件模板的数据处理和展示逻辑
- 在 EmailTemplateUtil 中增加了对 email 和 newPassword 的非空校验 - 更新了 notification.html、password-reset.html 和 register-success.html 模板中的条件判断逻辑 - 优化了模板的 HTML 结构和样式,提高了邮件的可读性和美观性
This commit is contained in:
@@ -37,7 +37,9 @@ public class EmailTemplateUtil {
|
||||
data.put("username", username);
|
||||
data.put("phone", phone);
|
||||
data.put("password", password);
|
||||
data.put("email", email);
|
||||
if (email != null && !email.trim().isEmpty()) {
|
||||
data.put("email", email);
|
||||
}
|
||||
|
||||
emailRecordService.sendHtmlEmail(title, "register-success.html", data, new String[]{email});
|
||||
} catch (Exception e) {
|
||||
@@ -62,8 +64,10 @@ public class EmailTemplateUtil {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("username", username);
|
||||
data.put("phone", phone);
|
||||
data.put("newPassword", newPassword);
|
||||
data.put("resetTime", DateUtil.now());
|
||||
if (newPassword != null && !newPassword.trim().isEmpty()) {
|
||||
data.put("newPassword", newPassword);
|
||||
}
|
||||
|
||||
emailRecordService.sendHtmlEmail(title, "password-reset.html", data, new String[]{email});
|
||||
} catch (Exception e) {
|
||||
@@ -93,16 +97,16 @@ public class EmailTemplateUtil {
|
||||
data.put("content", content);
|
||||
data.put("sendTime", DateUtil.now());
|
||||
|
||||
if (greeting != null) {
|
||||
if (greeting != null && !greeting.trim().isEmpty()) {
|
||||
data.put("greeting", greeting);
|
||||
}
|
||||
if (infoMessage != null) {
|
||||
if (infoMessage != null && !infoMessage.trim().isEmpty()) {
|
||||
data.put("infoMessage", infoMessage);
|
||||
}
|
||||
if (actionUrl != null) {
|
||||
if (actionUrl != null && !actionUrl.trim().isEmpty()) {
|
||||
data.put("actionUrl", actionUrl);
|
||||
}
|
||||
if (actionText != null) {
|
||||
if (actionText != null && !actionText.trim().isEmpty()) {
|
||||
data.put("actionText", actionText);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user