Separate second-factor verification and delivery from auth (#40)
This commit is contained in:
1 parent
12a38cd654
commit
ecb63b61c6
33 files changed
+1772
-123
No files matched your search
@@ -0,0 +1,23 @@
|
||||
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})
|
||||
}
|
||||
Reference in new issue
Block a user