Fixed auth email template handlers

This commit is contained in:
Denis Arh
2021-03-17 18:13:17 +01:00
parent 79ed77a379
commit 679fba69cc
2 changed files with 14 additions and 10 deletions
+4 -4
View File
@@ -17,13 +17,13 @@ templates:
<p>You will be logged-in after successful reset.</p>
{{template "email_general_footer" .}}
auth_email_email_confirm_subject:
auth_email_confirm_subject:
type: text/plain
meta:
short: Email confirmation subject
template: Reset your password
auth_email_email_confirm_content:
auth_email_confirm_content:
type: text/html
meta:
short: Email confirmation content
@@ -35,13 +35,13 @@ templates:
<p>You will be logged-in after successful confirmation.</p>
{{template "email_general_footer" .}}
auth_email_email_mfa_subject:
auth_email_mfa_subject:
type: text/plain
meta:
short: MFA login code subject
template: Login code
auth_email_email_mfa_content:
auth_email_mfa_content:
type: text/html
meta:
short: MFA login code content
+10 -6
View File
@@ -45,13 +45,13 @@ func (svc authNotification) log(ctx context.Context, fields ...zapcore.Field) *z
}
func (svc authNotification) EmailOTP(ctx context.Context, emailAddress string, code string) error {
return svc.send(ctx, "auth_email_otp", emailAddress, map[string]interface{}{
return svc.send(ctx, "auth_email_mfa", emailAddress, map[string]interface{}{
"Code": code,
})
}
func (svc authNotification) EmailConfirmation(ctx context.Context, emailAddress string, token string) error {
return svc.send(ctx, "auth_email_confirmation", emailAddress, map[string]interface{}{
return svc.send(ctx, "auth_email_confirm", emailAddress, map[string]interface{}{
"URL": fmt.Sprintf("%s/confirm-email?token=%s", svc.opt.BaseURL, url.QueryEscape(token)),
})
}
@@ -81,16 +81,20 @@ func (svc authNotification) send(ctx context.Context, name, sendTo string, paylo
err error
tmp []byte
ntf = svc.newMail()
hdl string
)
// Fetch parts
st, err := svc.ts.FindByHandle(ctx, name+"_subject")
hdl = name + "_subject"
st, err := svc.ts.FindByHandle(ctx, hdl)
if err != nil {
return err
return fmt.Errorf("cannot generate auth email with template %s: %w", hdl, err)
}
ct, err := svc.ts.FindByHandle(ctx, name+"_content")
hdl = name + "_content"
ct, err := svc.ts.FindByHandle(ctx, hdl)
if err != nil {
return err
return fmt.Errorf("cannot generate auth email with template %s: %w", hdl, err)
}
// Prepare payload