24 lines
1.0 KiB
Go
24 lines
1.0 KiB
Go
package delivery
|
|
|
|
import (
|
|
"context"
|
|
customer "git.sendico.io/tech/sxchnge/product/customers/model"
|
|
"git.sendico.io/tech/sxchnge/product/notifications"
|
|
model "git.sendico.io/tech/sxchnge/product/twofactor/model"
|
|
vmodel "git.sendico.io/tech/sxchnge/product/verification/model"
|
|
"git.sendico.io/tech/sxchnge/shared/logging/mask"
|
|
)
|
|
|
|
type Email struct{ Sender notifications.Sender }
|
|
|
|
func (Email) Channel() model.Channel { return model.Email }
|
|
func (Email) Normalize(address string) (string, error) { return customer.NormalizeEmail(address) }
|
|
func (Email) Mask(address string) string { return mask.Email(address) }
|
|
func (d Email) Send(ctx context.Context, m model.Delivery) error {
|
|
template := "twofactor.code"
|
|
if m.Scope.Purpose == vmodel.PurposeLogin {
|
|
template = "auth.login"
|
|
}
|
|
return d.Sender.Send(ctx, notifications.Message{Key: m.Key, UserID: m.Subject.Hex(), Email: m.Factor.Address, Locale: m.Locale, Template: template, Parameters: map[string]string{"code": m.Code}, ExpiresAt: m.ExpiresAt})
|
|
}
|