onasty/mailer/template.go (view raw)
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "fmt" |
| 6 | ) |
| 7 | |
| 8 | type Template struct { |
| 9 | Subject string |
| 10 | Body string |
| 11 | } |
| 12 | |
| 13 | type TemplateFunc func(args map[string]string) Template |
| 14 | |
| 15 | func getTemplate(appURL string, templateName string) (TemplateFunc, error) { |
| 16 | if templateName == "email_verification" { |
| 17 | return emailVerificationTemplate(appURL), nil |
| 18 | } |
| 19 | |
| 20 | return nil, errors.New("failed to get template") //nolint:err113 |
| 21 | } |
| 22 | |
| 23 | func emailVerificationTemplate(appURL string) TemplateFunc { |
| 24 | return func(opts map[string]string) Template { |
| 25 | return Template{ |
| 26 | Subject: "Onasty: verify your email", |
| 27 | Body: fmt.Sprintf(`To verify your email, please follow this link: |
| 28 | <a href="%[1]s/api/v1/auth/verify/%[2]s">%[1]s/api/v1/auth/verify/%[2]s</a> |
| 29 | <br /> |
| 30 | <br /> |
| 31 | This link will expire after 24 hours.`, appURL, opts["token"]), |
| 32 | } |
| 33 | } |
| 34 | } |