This commit is contained in:
eson 2023-09-04 10:59:17 +08:00
parent 9c013ac494
commit 88ae58c9d8
2 changed files with 9 additions and 28 deletions

View File

@ -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:
<a href="{{ConfirmationLink}}" target="_blank" style="background-color: #008CBA; color: #FFFFFF; text-decoration: none; padding: 10px 15px; border-radius: 3px; display:inline-block; font-weight: bold;">Confirm My Account</a>
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()
}

View File

@ -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)
}