Skip to content

Commit cbb83da

Browse files
fix(mailer): include SiteURL in notification template data
The seven notification mail builders (PasswordChanged, EmailChanged, PhoneChanged, IdentityLinked, IdentityUnlinked, MFAFactorEnrolled, MFAFactorUnenrolled) omitted SiteURL from their template data maps, so templates referencing {{ .SiteURL }} rendered an empty string at runtime. The standard mail builders (Invite, Confirmation, Recovery, MagicLink, EmailChange, Reauthentication) already include it, and checkDefaults whitelists SiteURL for all template types, so this was an oversight rather than an intentional restriction. Closes #2468
1 parent cda62a9 commit cbb83da

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

internal/mailer/templatemailer/templatemailer.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,16 @@ func (m *Mailer) GetEmailActionLink(user *models.User, actionType, referrerURL s
425425

426426
func (m *Mailer) PasswordChangedNotificationMail(r *http.Request, user *models.User) error {
427427
data := map[string]any{
428-
"Email": user.Email,
429-
"Data": user.UserMetaData,
428+
"SiteURL": m.cfg.SiteURL,
429+
"Email": user.Email,
430+
"Data": user.UserMetaData,
430431
}
431432
return m.mail(r.Context(), m.cfg, PasswordChangedNotificationTemplate, user.GetEmail(), data)
432433
}
433434

434435
func (m *Mailer) EmailChangedNotificationMail(r *http.Request, user *models.User, oldEmail string) error {
435436
data := map[string]any{
437+
"SiteURL": m.cfg.SiteURL,
436438
"Email": user.GetEmail(), // the new email address that has been set on the account
437439
"OldEmail": oldEmail, // the old email address that was on the account before the change
438440
"Data": user.UserMetaData,
@@ -442,6 +444,7 @@ func (m *Mailer) EmailChangedNotificationMail(r *http.Request, user *models.User
442444

443445
func (m *Mailer) PhoneChangedNotificationMail(r *http.Request, user *models.User, oldPhone string) error {
444446
data := map[string]any{
447+
"SiteURL": m.cfg.SiteURL,
445448
"Email": user.GetEmail(),
446449
"Phone": user.GetPhone(), // the new phone number that has been set on the account
447450
"OldPhone": oldPhone, // the old phone number that was on the account before the change
@@ -452,6 +455,7 @@ func (m *Mailer) PhoneChangedNotificationMail(r *http.Request, user *models.User
452455

453456
func (m *Mailer) IdentityLinkedNotificationMail(r *http.Request, user *models.User, provider string) error {
454457
data := map[string]any{
458+
"SiteURL": m.cfg.SiteURL,
455459
"Email": user.GetEmail(),
456460
"Provider": provider, // the provider of the newly linked identity
457461
"Data": user.UserMetaData,
@@ -461,6 +465,7 @@ func (m *Mailer) IdentityLinkedNotificationMail(r *http.Request, user *models.Us
461465

462466
func (m *Mailer) IdentityUnlinkedNotificationMail(r *http.Request, user *models.User, provider string) error {
463467
data := map[string]any{
468+
"SiteURL": m.cfg.SiteURL,
464469
"Email": user.GetEmail(),
465470
"Provider": provider, // the provider of the unlinked identity
466471
"Data": user.UserMetaData,
@@ -470,6 +475,7 @@ func (m *Mailer) IdentityUnlinkedNotificationMail(r *http.Request, user *models.
470475

471476
func (m *Mailer) MFAFactorEnrolledNotificationMail(r *http.Request, user *models.User, factorType string) error {
472477
data := map[string]any{
478+
"SiteURL": m.cfg.SiteURL,
473479
"Email": user.GetEmail(),
474480
"FactorType": factorType,
475481
"Data": user.UserMetaData,
@@ -479,6 +485,7 @@ func (m *Mailer) MFAFactorEnrolledNotificationMail(r *http.Request, user *models
479485

480486
func (m *Mailer) MFAFactorUnenrolledNotificationMail(r *http.Request, user *models.User, factorType string) error {
481487
data := map[string]any{
488+
"SiteURL": m.cfg.SiteURL,
482489
"Email": user.GetEmail(),
483490
"FactorType": factorType,
484491
"Data": user.UserMetaData,

0 commit comments

Comments
 (0)