unified code verification service
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -11,7 +12,7 @@ func (a *NotificationAPI) onAccount(context context.Context, account *model.Acco
|
||||
var link string
|
||||
var err error
|
||||
if link, err = a.dp.GetFullLink("verify", token); err != nil {
|
||||
a.logger.Warn("Failed to generate verification link", zap.Error(err), zap.String("login", account.Login))
|
||||
a.logger.Warn("Failed to generate verification link", zap.Error(err), mzap.Login(account))
|
||||
return err
|
||||
}
|
||||
mr := a.client.MailBuilder().
|
||||
@@ -21,9 +22,9 @@ func (a *NotificationAPI) onAccount(context context.Context, account *model.Acco
|
||||
AddButton(link).
|
||||
SetTemplateID("welcome")
|
||||
if err := a.client.Send(mr); err != nil {
|
||||
a.logger.Warn("Failed to send verification email", zap.Error(err), zap.String("login", account.Login))
|
||||
a.logger.Warn("Failed to send verification email", zap.Error(err), mzap.Login(account))
|
||||
return err
|
||||
}
|
||||
a.logger.Info("Verification email sent", zap.String("login", account.Login))
|
||||
a.logger.Info("Verification email sent", mzap.Login(account))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,23 +5,24 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (a *NotificationAPI) onConfirmationCode(ctx context.Context, account *model.Account, destination string, target model.ConfirmationTarget, code string) error {
|
||||
func (a *NotificationAPI) onConfirmationCode(ctx context.Context, account *model.Account, target string, purpose model.VerificationPurpose, code string) error {
|
||||
builder := a.client.MailBuilder().
|
||||
AddRecipient(account.Name, strings.TrimSpace(destination)).
|
||||
AddRecipient(account.Name, strings.TrimSpace(target)).
|
||||
SetAccountID(account.ID.Hex()).
|
||||
SetLocale(account.Locale).
|
||||
SetTemplateID("confirmation-code").
|
||||
AddData("Name", account.Name).
|
||||
AddData("Code", code).
|
||||
AddData("Target", string(target))
|
||||
AddData("Target", model.VPToString(purpose))
|
||||
|
||||
if err := a.client.Send(builder); err != nil {
|
||||
a.logger.Warn("Failed to send confirmation code email", zap.Error(err), zap.String("login", account.Login))
|
||||
a.logger.Warn("Failed to send confirmation code email", zap.Error(err), mzap.Login(account))
|
||||
return err
|
||||
}
|
||||
a.logger.Info("Confirmation code email sent", zap.String("login", account.Login), zap.String("destination", destination), zap.String("target", string(target)))
|
||||
a.logger.Info("Confirmation code email sent", mzap.Login(account), zap.String("destination", target), zap.String("target", string(purpose)))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -11,7 +12,7 @@ func (a *NotificationAPI) onPasswordReset(context context.Context, account *mode
|
||||
var link string
|
||||
var err error
|
||||
if link, err = a.dp.GetFullLink("password", "reset", account.ID.Hex(), resetToken); err != nil {
|
||||
a.logger.Warn("Failed to generate password reset link", zap.Error(err), zap.String("login", account.Login))
|
||||
a.logger.Warn("Failed to generate password reset link", zap.Error(err), mzap.Login(account))
|
||||
return err
|
||||
}
|
||||
mr := a.client.MailBuilder().
|
||||
@@ -22,9 +23,9 @@ func (a *NotificationAPI) onPasswordReset(context context.Context, account *mode
|
||||
AddData("URL", link).
|
||||
SetTemplateID("reset-password")
|
||||
if err := a.client.Send(mr); err != nil {
|
||||
a.logger.Warn("Failed to send password reset email", zap.Error(err), zap.String("login", account.Login))
|
||||
a.logger.Warn("Failed to send password reset email", zap.Error(err), mzap.Login(account))
|
||||
return err
|
||||
}
|
||||
a.logger.Info("Password reset email sent", zap.String("login", account.Login))
|
||||
a.logger.Info("Password reset email sent", mzap.Login(account))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user