From 88ae58c9d813324e4cb7d61b805fc95450fbd799 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 4 Sep 2023 10:59:17 +0800 Subject: [PATCH] fix --- server/auth/auth_test.go | 22 --------------------- server/auth/internal/logic/email_manager.go | 15 ++++++++------ 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/server/auth/auth_test.go b/server/auth/auth_test.go index e8b63634..80820ef2 100644 --- a/server/auth/auth_test.go +++ b/server/auth/auth_test.go @@ -4,28 +4,6 @@ import ( "testing" ) -const emailTemplate = `Subject: Please confirm your {{CompanyName}} account - -Dear , - -Thank you for registering an account with {{CompanyName}}. We are thrilled to have you join our community! - -Please take a moment to confirm your email address by clicking the button below so we can activate your account: - -Confirm My Account - -Confirming your email ensures your account is properly secured. This also lets you access member-only tools and content. - -If you did not register for {{CompanyName}}, please disregard this email. Let us know if you have any other questions! - -Regards, - -{{SenderName}} -{{SenderTitle}} -{{CompanyName}} -` - func TestMain(t *testing.T) { - main() } diff --git a/server/auth/internal/logic/email_manager.go b/server/auth/internal/logic/email_manager.go index 6a678386..8c0adfab 100644 --- a/server/auth/internal/logic/email_manager.go +++ b/server/auth/internal/logic/email_manager.go @@ -16,8 +16,16 @@ var EmailTaskResendTime = time.Second * 30 var TimeLimit *check.TimeLimit[string] var EmailManager *EmailSender +var emailTpl *template.Template + func init() { + tmpl, err := template.New("email").ParseFiles("../../html_template/email_register.tpl") + if err != nil { + log.Fatal(err) + } + emailTpl = tmpl + TimeLimit = check.NewTimelimit[string](EmailTaskResendTime) // Initialize the email manager @@ -149,11 +157,6 @@ func (m *EmailSender) ClearExpiredTasks() { func RenderEmailTemplate(companyName, confirmationLink, senderName, senderTitle string) []byte { - tmpl, err := template.New("email").ParseFiles("../../html_template/email_register.tpl") - if err != nil { - log.Fatal(err) - } - data := map[string]string{ "CompanyName": companyName, "ConfirmationLink": confirmationLink, @@ -162,7 +165,7 @@ func RenderEmailTemplate(companyName, confirmationLink, senderName, senderTitle } var result bytes.Buffer - err = tmpl.Execute(&result, data) + err := emailTpl.Execute(&result, data) if err != nil { log.Fatal(err) }