3
0

Remove lang param from auth notifications

This commit is contained in:
Denis Arh
2021-03-11 21:19:00 +01:00
parent 7979fba9be
commit 3649da2967
3 changed files with 16 additions and 24 deletions

View File

@@ -102,7 +102,7 @@ func Auth(app serviceInitializer, opt options.AuthOpt) *cobra.Command {
// Update current settings to be sure that we do not have outdated values
cli.HandleError(service.DefaultSettings.UpdateCurrent(ctx))
err = ntf.PasswordReset(ctx, "en", args[0], "notification-testing-token")
err = ntf.PasswordReset(ctx, args[0], "notification-testing-token")
cli.HandleError(err)
},
}

View File

@@ -733,8 +733,7 @@ func (svc auth) ExchangePasswordResetToken(ctx context.Context, token string) (u
func (svc auth) SendEmailAddressConfirmationToken(ctx context.Context, u *types.User) (err error) {
var (
notificationLang = "en"
token string
token string
aam = &authActionProps{
user: u,
@@ -746,7 +745,7 @@ func (svc auth) SendEmailAddressConfirmationToken(ctx context.Context, u *types.
return
}
if err = svc.notifications.EmailConfirmation(ctx, notificationLang, u.Email, token); err != nil {
if err = svc.notifications.EmailConfirmation(ctx, u.Email, token); err != nil {
return
}
@@ -786,16 +785,12 @@ func (svc auth) SendPasswordResetToken(ctx context.Context, email string) (err e
}
func (svc auth) sendPasswordResetToken(ctx context.Context, u *types.User) (err error) {
var (
notificationLang = "en"
)
token, err := svc.createUserToken(ctx, u, credentialsTypeResetPasswordToken)
if err != nil {
return err
}
return svc.notifications.PasswordReset(ctx, notificationLang, u.Email, token)
return svc.notifications.PasswordReset(ctx, u.Email, token)
}
// procLogin fn performs standard validation, credentials-update tasks and triggers events
@@ -1186,8 +1181,6 @@ func (auth) revokeAllTOTP(ctx context.Context, s store.Credentials, userID uint6
func (svc auth) SendEmailOTP(ctx context.Context) (err error) {
var (
notificationLang = "en"
otp string
u *types.User
kind = credentialsTypeMFAEmailOTP
@@ -1211,7 +1204,7 @@ func (svc auth) SendEmailOTP(ctx context.Context) (err error) {
return
}
if err = svc.notifications.EmailOTP(ctx, notificationLang, u.Email, otp); err != nil {
if err = svc.notifications.EmailOTP(ctx, u.Email, otp); err != nil {
return
}

View File

@@ -25,13 +25,13 @@ type (
}
AuthNotificationService interface {
EmailOTP(ctx context.Context, lang string, emailAddress string, otp string) error
EmailConfirmation(ctx context.Context, lang string, emailAddress string, url string) error
PasswordReset(ctx context.Context, lang string, emailAddress string, url string) error
EmailOTP(ctx context.Context, emailAddress string, otp string) error
EmailConfirmation(ctx context.Context, emailAddress string, url string) error
PasswordReset(ctx context.Context, emailAddress string, url string) error
}
)
func AuthNotification(s *types.AppSettings, ts TemplateService, opt options.AuthOpt) AuthNotificationService {
func AuthNotification(s *types.AppSettings, ts TemplateService, opt options.AuthOpt) *authNotification {
return &authNotification{
logger: DefaultLogger.Named("auth-notification"),
settings: s,
@@ -44,20 +44,20 @@ func (svc authNotification) log(ctx context.Context, fields ...zapcore.Field) *z
return logger.AddRequestID(ctx, svc.logger).With(fields...)
}
func (svc authNotification) EmailOTP(ctx context.Context, lang string, emailAddress string, code string) error {
return svc.send(ctx, "auth_email_otp", lang, emailAddress, map[string]interface{}{
func (svc authNotification) EmailOTP(ctx context.Context, emailAddress string, code string) error {
return svc.send(ctx, "auth_email_otp", emailAddress, map[string]interface{}{
"Code": code,
})
}
func (svc authNotification) EmailConfirmation(ctx context.Context, lang string, emailAddress string, token string) error {
return svc.send(ctx, "auth_email_confirmation", lang, emailAddress, map[string]interface{}{
func (svc authNotification) EmailConfirmation(ctx context.Context, emailAddress string, token string) error {
return svc.send(ctx, "auth_email_confirmation", emailAddress, map[string]interface{}{
"URL": fmt.Sprintf("%s/confirm-email?token=%s", svc.opt.BaseURL, url.QueryEscape(token)),
})
}
func (svc authNotification) PasswordReset(ctx context.Context, lang string, emailAddress string, token string) error {
return svc.send(ctx, "auth_email_password_reset", lang, emailAddress, map[string]interface{}{
func (svc authNotification) PasswordReset(ctx context.Context, emailAddress string, token string) error {
return svc.send(ctx, "auth_email_password_reset", emailAddress, map[string]interface{}{
"URL": fmt.Sprintf("%s/reset-password?token=%s", svc.opt.BaseURL, url.QueryEscape(token)),
})
}
@@ -76,7 +76,7 @@ func (svc authNotification) newMail() *gomail.Message {
return m
}
func (svc authNotification) send(ctx context.Context, name, lang, sendTo string, payload map[string]interface{}) error {
func (svc authNotification) send(ctx context.Context, name, sendTo string, payload map[string]interface{}) error {
var (
err error
tmp []byte
@@ -126,7 +126,6 @@ func (svc authNotification) send(ctx context.Context, name, lang, sendTo string,
svc.log(ctx).Debug(
"sending auth notification",
zap.String("name", name),
zap.String("language", lang),
zap.String("email", sendTo),
)