This commit is contained in:
eson 2023-09-04 11:32:17 +08:00
parent 88ae58c9d8
commit 8a20bda390
5 changed files with 39 additions and 12 deletions

View File

@ -1,19 +1,19 @@
Subject: Please confirm your {{.CompanyName}} account Subject: Please confirm your {{ .CompanyName }} account
Dear , Dear,
Thank you for registering an account with {{.CompanyName}}. We are thrilled to have you join our community! 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: 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> <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. 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! If you did not register for {{ .CompanyName }}, please disregard this email. Let us know if you have any other questions!
Regards, Regards,
{{.SenderName}} {{ .SenderName }}
{{.SenderTitle}} {{ .SenderTitle }}
{{.CompanyName}} {{ .CompanyName }}

View File

@ -5,5 +5,6 @@ import (
) )
func TestMain(t *testing.T) { func TestMain(t *testing.T) {
main() main()
} }

View File

@ -16,15 +16,15 @@ var EmailTaskResendTime = time.Second * 30
var TimeLimit *check.TimeLimit[string] var TimeLimit *check.TimeLimit[string]
var EmailManager *EmailSender var EmailManager *EmailSender
var emailTpl *template.Template var tpls *template.Template
func init() { func init() {
var err error
tmpl, err := template.New("email").ParseFiles("../../html_template/email_register.tpl") tpls, err = template.ParseGlob("../../../../html_template/*.tpl")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
emailTpl = tmpl
TimeLimit = check.NewTimelimit[string](EmailTaskResendTime) TimeLimit = check.NewTimelimit[string](EmailTaskResendTime)
@ -165,7 +165,7 @@ func RenderEmailTemplate(companyName, confirmationLink, senderName, senderTitle
} }
var result bytes.Buffer var result bytes.Buffer
err := emailTpl.Execute(&result, data) err := tpls.ExecuteTemplate(&result, "email_register.tpl", data)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -1,6 +1,7 @@
package logic package logic
import ( import (
"bytes"
"fmt" "fmt"
"fusenapi/utils/wevent" "fusenapi/utils/wevent"
"log" "log"
@ -11,6 +12,24 @@ import (
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
) )
func TestEmailTpl(t *testing.T) {
data := map[string]string{
"CompanyName": "companyName",
"ConfirmationLink": "confirmationLink",
"SenderName": "senderName",
"SenderTitle": "senderTitle",
}
var result bytes.Buffer
err := tpls.ExecuteTemplate(&result, "email_register.tpl", data)
if err != nil {
log.Fatal(err)
}
log.Println(string(result.String()))
}
func TestSender(t *testing.T) { func TestSender(t *testing.T) {
traceId := uuid.NewString() traceId := uuid.NewString()
event := wevent.NewWebsocketEventSuccess(wevent.UserEmailRegister, traceId) event := wevent.NewWebsocketEventSuccess(wevent.UserEmailRegister, traceId)

View File

@ -0,0 +1,7 @@
package fstpl
import "html/template"
func ParseFile(t *template.Template) {
}