diff --git a/backend/dto/webhook/email.go b/backend/dto/webhook/email.go index 7d33e4886..9ebda1a38 100644 --- a/backend/dto/webhook/email.go +++ b/backend/dto/webhook/email.go @@ -1,14 +1,14 @@ package webhook type EmailSend struct { - Subject string `json:"subject"` // subject - BodyPlain string `json:"body_plain"` // used for string templates - Body string `json:"body,omitempty"` // used for HTML templates - ToEmailAddress string `json:"to_email_address"` - DeliveredByHanko bool `json:"delivered_by_hanko"` - AcceptLanguage string `json:"accept_language"` // Deprecated. Accept-Language header from HTTP request - Language string `json:"language"` // X-Language header from HTTP request - Type EmailType `json:"type"` // type of the email, currently only "passcode", but other could be added later + Subject string `json:"subject"` // subject + BodyPlain string `json:"body_plain"` // used for string templates + Body string `json:"body,omitempty"` // used for HTML templates + ToEmailAddress string `json:"to_email_address"` + DeliveredByHanko bool `json:"delivered_by_hanko"` + AcceptLanguage string `json:"accept_language"` // Deprecated. Accept-Language header from HTTP request + Language string `json:"language"` // X-Language header from HTTP request + Type string `json:"type"` // type of the email Data interface{} `json:"data"` } @@ -19,9 +19,3 @@ type PasscodeData struct { TTL int `json:"ttl"` ValidUntil int64 `json:"valid_until"` // UnixTimestamp } - -type EmailType string - -var ( - EmailTypePasscode EmailType = "passcode" -) diff --git a/backend/flow_api/flow/credential_usage/action_resend_passcode.go b/backend/flow_api/flow/credential_usage/action_resend_passcode.go index b75c31d4e..03f59c3a4 100644 --- a/backend/flow_api/flow/credential_usage/action_resend_passcode.go +++ b/backend/flow_api/flow/credential_usage/action_resend_passcode.go @@ -54,8 +54,10 @@ func (a ReSendPasscode) Execute(c flowpilot.ExecutionContext) error { } } + passcodeTemplate := c.Stash().Get(shared.StashPathPasscodeTemplate).String() + sendParams := services.SendPasscodeParams{ - Template: c.Stash().Get(shared.StashPathPasscodeTemplate).String(), + Template: passcodeTemplate, EmailAddress: c.Stash().Get(shared.StashPathEmail).String(), Language: deps.HttpContext.Request().Header.Get("X-Language"), } @@ -71,7 +73,7 @@ func (a ReSendPasscode) Execute(c flowpilot.ExecutionContext) error { DeliveredByHanko: deps.Cfg.EmailDelivery.Enabled, AcceptLanguage: sendParams.Language, Language: sendParams.Language, - Type: webhook.EmailTypePasscode, + Type: passcodeTemplate, Data: webhook.PasscodeData{ ServiceName: deps.Cfg.Service.Name, OtpCode: passcodeResult.Code, diff --git a/backend/flow_api/flow/credential_usage/hook_send_passcode.go b/backend/flow_api/flow/credential_usage/hook_send_passcode.go index f16494248..699799fb2 100644 --- a/backend/flow_api/flow/credential_usage/hook_send_passcode.go +++ b/backend/flow_api/flow/credential_usage/hook_send_passcode.go @@ -63,9 +63,11 @@ func (h SendPasscode) Execute(c flowpilot.HookExecutionContext) error { isDifferentEmailAddress := c.Stash().Get(shared.StashPathEmail).String() != c.Stash().Get(shared.StashPathPasscodeEmail).String() + passcodeTemplate := c.Stash().Get(shared.StashPathPasscodeTemplate).String() + if !passcodeIsValid || isDifferentEmailAddress { sendParams := services.SendPasscodeParams{ - Template: c.Stash().Get(shared.StashPathPasscodeTemplate).String(), + Template: passcodeTemplate, EmailAddress: c.Stash().Get(shared.StashPathEmail).String(), Language: deps.HttpContext.Request().Header.Get("X-Language"), } @@ -92,7 +94,7 @@ func (h SendPasscode) Execute(c flowpilot.HookExecutionContext) error { DeliveredByHanko: deps.Cfg.EmailDelivery.Enabled, AcceptLanguage: sendParams.Language, Language: sendParams.Language, - Type: webhook.EmailTypePasscode, + Type: passcodeTemplate, Data: webhook.PasscodeData{ ServiceName: deps.Cfg.Service.Name, OtpCode: passcodeResult.Code, diff --git a/backend/handler/passcode.go b/backend/handler/passcode.go index 53e8a28e3..62b76a99f 100644 --- a/backend/handler/passcode.go +++ b/backend/handler/passcode.go @@ -207,7 +207,7 @@ func (h *PasscodeHandler) Init(c echo.Context) error { DeliveredByHanko: true, AcceptLanguage: lang, Language: lang, - Type: webhook.EmailTypePasscode, + Type: "passcode", Data: webhook.PasscodeData{ ServiceName: h.cfg.Service.Name, OtpCode: passcode,