mirror of
https://github.com/volatiletech/authboss.git
synced 2025-03-05 15:15:45 +02:00
Rename Localize to Localizef
This commit is contained in:
parent
a0994c3732
commit
3abb766478
@ -63,7 +63,7 @@ func (a *Auth) LoginPost(w http.ResponseWriter, r *http.Request) error {
|
||||
pidUser, err := a.Authboss.Storage.Server.Load(r.Context(), pid)
|
||||
if err == authboss.ErrUserNotFound {
|
||||
logger.Infof("failed to load user requested by pid: %s", pid)
|
||||
data := authboss.HTMLData{authboss.DataErr: a.Localize(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
data := authboss.HTMLData{authboss.DataErr: a.Localizef(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
return a.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageLogin, data)
|
||||
} else if err != nil {
|
||||
return err
|
||||
@ -85,7 +85,7 @@ func (a *Auth) LoginPost(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
logger.Infof("user %s failed to log in", pid)
|
||||
data := authboss.HTMLData{authboss.DataErr: a.Localize(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
data := authboss.HTMLData{authboss.DataErr: a.Localizef(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
return a.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageLogin, data)
|
||||
}
|
||||
|
||||
|
@ -101,15 +101,15 @@ func (a *Authboss) VerifyPassword(user AuthableUser, password string) error {
|
||||
return a.Core.Hasher.CompareHashAndPassword(user.GetPassword(), password)
|
||||
}
|
||||
|
||||
// Localize is a helper to translate a key using the translator
|
||||
// Localizef is a helper to translate a key using the translator
|
||||
// If the localizer is nil or returns an empty string,
|
||||
// then the original text will be returned using [fmt.Sprintf] to interpolate the args.
|
||||
func (a *Authboss) Localize(ctx context.Context, text string, args ...any) string {
|
||||
func (a *Authboss) Localizef(ctx context.Context, text string, args ...any) string {
|
||||
if a.Config.Core.Localizer == nil {
|
||||
return fmt.Sprintf(text, args...)
|
||||
}
|
||||
|
||||
if translated := a.Config.Core.Localizer.Localize(ctx, text, args...); translated != "" {
|
||||
if translated := a.Config.Core.Localizer.Localizef(ctx, text, args...); translated != "" {
|
||||
return translated
|
||||
}
|
||||
|
||||
@ -231,7 +231,7 @@ func MountedMiddleware2(ab *Authboss, mountPathed bool, reqs MWRequirements, fai
|
||||
|
||||
ro := RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: ab.Localize(r.Context(), TxtAuthFailed),
|
||||
Failure: ab.Localizef(r.Context(), TxtAuthFailed),
|
||||
RedirectPath: path.Join(ab.Config.Paths.Mount, fmt.Sprintf("/login?%s", vals.Encode())),
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ func (c *Confirm) PreventAuth(w http.ResponseWriter, r *http.Request, handled bo
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
RedirectPath: c.Authboss.Config.Paths.ConfirmNotOK,
|
||||
Failure: c.Localize(r.Context(), authboss.TxtAccountNotConfirmed),
|
||||
Failure: c.Localizef(r.Context(), authboss.TxtAccountNotConfirmed),
|
||||
}
|
||||
return true, c.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
}
|
||||
@ -114,7 +114,7 @@ func (c *Confirm) StartConfirmationWeb(w http.ResponseWriter, r *http.Request, h
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
RedirectPath: c.Authboss.Config.Paths.ConfirmNotOK,
|
||||
Success: c.Localize(r.Context(), authboss.TxtConfirmYourAccount),
|
||||
Success: c.Localizef(r.Context(), authboss.TxtConfirmYourAccount),
|
||||
}
|
||||
return true, c.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
}
|
||||
@ -157,7 +157,7 @@ func (c *Confirm) SendConfirmEmail(ctx context.Context, to, token string) {
|
||||
To: []string{to},
|
||||
From: c.Config.Mail.From,
|
||||
FromName: c.Config.Mail.FromName,
|
||||
Subject: c.Config.Mail.SubjectPrefix + c.Localize(ctx, authboss.TxtConfirmEmailSubject),
|
||||
Subject: c.Config.Mail.SubjectPrefix + c.Localizef(ctx, authboss.TxtConfirmEmailSubject),
|
||||
}
|
||||
|
||||
logger.Infof("sending confirm e-mail to: %s", to)
|
||||
@ -236,7 +236,7 @@ func (c *Confirm) Get(w http.ResponseWriter, r *http.Request) error {
|
||||
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Success: c.Localize(r.Context(), authboss.TxtConfrimationSuccess),
|
||||
Success: c.Localizef(r.Context(), authboss.TxtConfrimationSuccess),
|
||||
RedirectPath: c.Authboss.Config.Paths.ConfirmOK,
|
||||
}
|
||||
return c.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
@ -256,7 +256,7 @@ func (c *Confirm) mailURL(token string) string {
|
||||
func (c *Confirm) invalidToken(w http.ResponseWriter, r *http.Request) error {
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: c.Localize(r.Context(), authboss.TxtInvalidConfirmToken),
|
||||
Failure: c.Localizef(r.Context(), authboss.TxtInvalidConfirmToken),
|
||||
RedirectPath: c.Authboss.Config.Paths.ConfirmNotOK,
|
||||
}
|
||||
return c.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
@ -284,7 +284,7 @@ func Middleware(ab *authboss.Authboss) func(http.Handler) http.Handler {
|
||||
logger.Infof("user %s prevented from accessing %s: not confirmed", user.GetPID(), r.URL.Path)
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: ab.Localize(r.Context(), authboss.TxtAccountNotConfirmed),
|
||||
Failure: ab.Localizef(r.Context(), authboss.TxtAccountNotConfirmed),
|
||||
RedirectPath: ab.Config.Paths.ConfirmNotOK,
|
||||
}
|
||||
if err := ab.Config.Core.Redirector.Redirect(w, r, ro); err != nil {
|
||||
|
@ -235,7 +235,7 @@ func TestGetValidationFailure(t *testing.T) {
|
||||
if p := harness.redirector.Options.RedirectPath; p != harness.ab.Paths.ConfirmNotOK {
|
||||
t.Error("redir path was wrong:", p)
|
||||
}
|
||||
if reason := harness.redirector.Options.Failure; reason != harness.ab.Localize(context.Background(), authboss.TxtInvalidConfirmToken) {
|
||||
if reason := harness.redirector.Options.Failure; reason != harness.ab.Localizef(context.Background(), authboss.TxtInvalidConfirmToken) {
|
||||
t.Error("reason for failure was wrong:", reason)
|
||||
}
|
||||
}
|
||||
@ -262,7 +262,7 @@ func TestGetBase64DecodeFailure(t *testing.T) {
|
||||
if p := harness.redirector.Options.RedirectPath; p != harness.ab.Paths.ConfirmNotOK {
|
||||
t.Error("redir path was wrong:", p)
|
||||
}
|
||||
if reason := harness.redirector.Options.Failure; reason != harness.ab.Localize(context.Background(), authboss.TxtInvalidConfirmToken) {
|
||||
if reason := harness.redirector.Options.Failure; reason != harness.ab.Localizef(context.Background(), authboss.TxtInvalidConfirmToken) {
|
||||
t.Error("reason for failure was wrong:", reason)
|
||||
}
|
||||
}
|
||||
@ -294,7 +294,7 @@ func TestGetUserNotFoundFailure(t *testing.T) {
|
||||
if p := harness.redirector.Options.RedirectPath; p != harness.ab.Paths.ConfirmNotOK {
|
||||
t.Error("redir path was wrong:", p)
|
||||
}
|
||||
if reason := harness.redirector.Options.Failure; reason != harness.ab.Localize(context.Background(), authboss.TxtInvalidConfirmToken) {
|
||||
if reason := harness.redirector.Options.Failure; reason != harness.ab.Localizef(context.Background(), authboss.TxtInvalidConfirmToken) {
|
||||
t.Error("reason for failure was wrong:", reason)
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package authboss
|
||||
|
||||
import "context"
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Localizer interface {
|
||||
// Get the translation for the given text in the given context.
|
||||
// If no translation is found, an empty string should be returned.
|
||||
Localize(ctx context.Context, txt string, args ...any) string
|
||||
Localizef(ctx context.Context, txt string, args ...any) string
|
||||
}
|
||||
|
||||
// Translation constants
|
||||
|
@ -99,7 +99,7 @@ func (l *Lock) updateLockedState(w http.ResponseWriter, r *http.Request, wasCorr
|
||||
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: l.Localize(r.Context(), authboss.TxtLocked),
|
||||
Failure: l.Localizef(r.Context(), authboss.TxtLocked),
|
||||
RedirectPath: l.Authboss.Config.Paths.LockNotOK,
|
||||
}
|
||||
return true, l.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
@ -158,7 +158,7 @@ func Middleware(ab *authboss.Authboss) func(http.Handler) http.Handler {
|
||||
logger.Infof("user %s prevented from accessing %s: locked", user.GetPID(), r.URL.Path)
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: ab.Localize(r.Context(), authboss.TxtLocked),
|
||||
Failure: ab.Localizef(r.Context(), authboss.TxtLocked),
|
||||
RedirectPath: ab.Config.Paths.LockNotOK,
|
||||
}
|
||||
if err := ab.Config.Core.Redirector.Redirect(w, r, ro); err != nil {
|
||||
|
@ -212,7 +212,7 @@ func (o *OAuth2) End(w http.ResponseWriter, r *http.Request) error {
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
RedirectPath: o.Authboss.Config.Paths.OAuth2LoginNotOK,
|
||||
Failure: o.Localize(r.Context(), authboss.TxtOAuth2LoginNotOK, provider),
|
||||
Failure: o.Localizef(r.Context(), authboss.TxtOAuth2LoginNotOK, provider),
|
||||
}
|
||||
return o.Authboss.Core.Redirector.Redirect(w, r, ro)
|
||||
}
|
||||
@ -290,7 +290,7 @@ func (o *OAuth2) End(w http.ResponseWriter, r *http.Request) error {
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
RedirectPath: redirect,
|
||||
Success: o.Localize(r.Context(), authboss.TxtOAuth2LoginOK, provider),
|
||||
Success: o.Localizef(r.Context(), authboss.TxtOAuth2LoginOK, provider),
|
||||
}
|
||||
return o.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ func (o *OTP) LoginPost(w http.ResponseWriter, r *http.Request) error {
|
||||
pidUser, err := o.Authboss.Storage.Server.Load(r.Context(), pid)
|
||||
if err == authboss.ErrUserNotFound {
|
||||
logger.Infof("failed to load user requested by pid: %s", pid)
|
||||
data := authboss.HTMLData{authboss.DataErr: o.Localize(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
data := authboss.HTMLData{authboss.DataErr: o.Localizef(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
return o.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageLogin, data)
|
||||
} else if err != nil {
|
||||
return err
|
||||
@ -153,7 +153,7 @@ func (o *OTP) LoginPost(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
logger.Infof("user %s failed to log in with otp", pid)
|
||||
data := authboss.HTMLData{authboss.DataErr: o.Localize(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
data := authboss.HTMLData{authboss.DataErr: o.Localizef(r.Context(), authboss.TxtInvalidCredentials)}
|
||||
return o.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageLogin, data)
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ func (o *OTP) AddPost(w http.ResponseWriter, r *http.Request) error {
|
||||
currentOTPs := splitOTPs(otpUser.GetOTPs())
|
||||
|
||||
if len(currentOTPs) >= maxOTPs {
|
||||
data := authboss.HTMLData{authboss.DataValidation: o.Localize(r.Context(), authboss.TxtTooManyOTPs, maxOTPs)}
|
||||
data := authboss.HTMLData{authboss.DataValidation: o.Localizef(r.Context(), authboss.TxtTooManyOTPs, maxOTPs)}
|
||||
return o.Core.Responder.Respond(w, r, http.StatusOK, PageAdd, data)
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ func (s *SMS) PostSetup(w http.ResponseWriter, r *http.Request) error {
|
||||
if len(number) == 0 {
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValuePhoneNumber: {
|
||||
s.Localize(r.Context(), authboss.TxtSMSNumberRequired),
|
||||
s.Localizef(r.Context(), authboss.TxtSMSNumberRequired),
|
||||
}},
|
||||
}
|
||||
return s.Core.Responder.Respond(w, r, http.StatusOK, PageSMSSetup, data)
|
||||
@ -357,7 +357,7 @@ func (s *SMSValidator) sendCode(w http.ResponseWriter, r *http.Request, user Use
|
||||
var data authboss.HTMLData
|
||||
err := s.SendCodeToUser(w, r, user.GetPID(), phoneNumber)
|
||||
if err == errSMSRateLimit {
|
||||
data = authboss.HTMLData{authboss.DataErr: s.Localize(r.Context(), authboss.TxtSMSWaitToResend)}
|
||||
data = authboss.HTMLData{authboss.DataErr: s.Localizef(r.Context(), authboss.TxtSMSWaitToResend)}
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -403,7 +403,7 @@ func (s *SMSValidator) validateCode(w http.ResponseWriter, r *http.Request, user
|
||||
|
||||
logger.Infof("user %s sms 2fa failure (wrong code)", user.GetPID())
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {s.Localize(r.Context(), authboss.TxtInvalid2FACode)}},
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {s.Localizef(r.Context(), authboss.TxtInvalid2FACode)}},
|
||||
}
|
||||
return s.Authboss.Core.Responder.Respond(w, r, http.StatusOK, s.Page, data)
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ func TestPostSetup(t *testing.T) {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
validation := h.responder.Data[authboss.DataValidation].(map[string][]string)
|
||||
if got := validation[FormValuePhoneNumber][0]; got != h.ab.Localize(context.Background(), authboss.TxtSMSNumberRequired) {
|
||||
if got := validation[FormValuePhoneNumber][0]; got != h.ab.Localizef(context.Background(), authboss.TxtSMSNumberRequired) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -547,7 +547,7 @@ func TestValidatorPostOk(t *testing.T) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
validation := h.responder.Data[authboss.DataValidation].(map[string][]string)
|
||||
if got := validation[FormValueCode][0]; got != h.ab.Localize(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
if got := validation[FormValueCode][0]; got != h.ab.Localizef(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -574,7 +574,7 @@ func TestValidatorPostOk(t *testing.T) {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
validation := h.responder.Data[authboss.DataValidation].(map[string][]string)
|
||||
if got := validation[FormValueCode][0]; got != h.ab.Localize(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
if got := validation[FormValueCode][0]; got != h.ab.Localizef(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
|
@ -269,7 +269,7 @@ func (t *TOTP) PostConfirm(w http.ResponseWriter, r *http.Request) error {
|
||||
if !ok {
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {
|
||||
t.Localize(r.Context(), authboss.TxtInvalid2FACode),
|
||||
t.Localizef(r.Context(), authboss.TxtInvalid2FACode),
|
||||
}},
|
||||
DataTOTPSecret: totpSecret,
|
||||
}
|
||||
@ -325,11 +325,11 @@ func (t *TOTP) PostRemove(w http.ResponseWriter, r *http.Request) error {
|
||||
user, status, err := t.validate(r)
|
||||
switch {
|
||||
case err == errNoTOTPEnabled:
|
||||
data := authboss.HTMLData{authboss.DataErr: t.Localize(r.Context(), authboss.TxtTOTP2FANotActive)}
|
||||
data := authboss.HTMLData{authboss.DataErr: t.Localizef(r.Context(), authboss.TxtTOTP2FANotActive)}
|
||||
return t.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageTOTPRemove, data)
|
||||
case err != nil:
|
||||
return err
|
||||
case status != t.Localize(r.Context(), authboss.TxtSuccess):
|
||||
case status != t.Localizef(r.Context(), authboss.TxtSuccess):
|
||||
logger.Infof("user %s totp 2fa removal failure (%s)", user.GetPID(), status)
|
||||
data := authboss.HTMLData{
|
||||
authboss.DataValidation: map[string][]string{FormValueCode: {status}},
|
||||
@ -368,12 +368,12 @@ func (t *TOTP) PostValidate(w http.ResponseWriter, r *http.Request) error {
|
||||
switch {
|
||||
case err == errNoTOTPEnabled:
|
||||
logger.Infof("user %s totp failure (not enabled)", user.GetPID())
|
||||
data := authboss.HTMLData{authboss.DataErr: t.Localize(
|
||||
data := authboss.HTMLData{authboss.DataErr: t.Localizef(
|
||||
r.Context(), authboss.TxtTOTP2FANotActive)}
|
||||
return t.Authboss.Core.Responder.Respond(w, r, http.StatusOK, PageTOTPValidate, data)
|
||||
case err != nil:
|
||||
return err
|
||||
case status != t.Localize(r.Context(), authboss.TxtSuccess):
|
||||
case status != t.Localizef(r.Context(), authboss.TxtSuccess):
|
||||
r = r.WithContext(context.WithValue(r.Context(), authboss.CTXKeyUser, user))
|
||||
handled, err := t.Authboss.Events.FireAfter(authboss.EventAuthFail, w, r)
|
||||
if err != nil {
|
||||
@ -471,10 +471,10 @@ func (t *TOTP) validate(r *http.Request) (User, string, error) {
|
||||
return nil, "", err
|
||||
}
|
||||
} else {
|
||||
return user, t.Localize(r.Context(), authboss.TxtInvalid2FACode), nil
|
||||
return user, t.Localizef(r.Context(), authboss.TxtInvalid2FACode), nil
|
||||
}
|
||||
|
||||
return user, t.Localize(r.Context(), authboss.TxtSuccess), nil
|
||||
return user, t.Localizef(r.Context(), authboss.TxtSuccess), nil
|
||||
}
|
||||
|
||||
input := totpCodeValues.GetCode()
|
||||
@ -482,14 +482,14 @@ func (t *TOTP) validate(r *http.Request) (User, string, error) {
|
||||
if oneTime, ok := user.(UserOneTime); ok {
|
||||
oldCode := oneTime.GetTOTPLastCode()
|
||||
if oldCode == input {
|
||||
return user, t.Localize(r.Context(), authboss.TxtRepeated2FACode), nil
|
||||
return user, t.Localizef(r.Context(), authboss.TxtRepeated2FACode), nil
|
||||
}
|
||||
oneTime.PutTOTPLastCode(input)
|
||||
}
|
||||
|
||||
if !totp.Validate(input, secret) {
|
||||
return user, t.Localize(r.Context(), authboss.TxtInvalid2FACode), nil
|
||||
return user, t.Localizef(r.Context(), authboss.TxtInvalid2FACode), nil
|
||||
}
|
||||
|
||||
return user, t.Localize(r.Context(), authboss.TxtSuccess), nil
|
||||
return user, t.Localizef(r.Context(), authboss.TxtSuccess), nil
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ func TestPostRemove(t *testing.T) {
|
||||
if h.responder.Page != PageTOTPRemove {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
if got := h.responder.Data[authboss.DataErr]; got != h.ab.Localize(context.Background(), authboss.TxtTOTP2FANotActive) {
|
||||
if got := h.responder.Data[authboss.DataErr]; got != h.ab.Localizef(context.Background(), authboss.TxtTOTP2FANotActive) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -404,7 +404,7 @@ func TestPostRemove(t *testing.T) {
|
||||
if h.responder.Page != PageTOTPRemove {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localize(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localizef(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -486,7 +486,7 @@ func TestPostValidate(t *testing.T) {
|
||||
if h.responder.Page != PageTOTPValidate {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
if got := h.responder.Data[authboss.DataErr]; got != h.ab.Localize(context.Background(), authboss.TxtTOTP2FANotActive) {
|
||||
if got := h.responder.Data[authboss.DataErr]; got != h.ab.Localizef(context.Background(), authboss.TxtTOTP2FANotActive) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -509,7 +509,7 @@ func TestPostValidate(t *testing.T) {
|
||||
if h.responder.Page != PageTOTPValidate {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localize(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localizef(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -533,7 +533,7 @@ func TestPostValidate(t *testing.T) {
|
||||
if h.responder.Page != PageTOTPValidate {
|
||||
t.Error("page wrong:", h.responder.Page)
|
||||
}
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localize(context.Background(), authboss.TxtRepeated2FACode) {
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localizef(context.Background(), authboss.TxtRepeated2FACode) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
@ -621,7 +621,7 @@ func TestPostValidate(t *testing.T) {
|
||||
// Flush client state
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localize(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
if got := h.responder.Data[authboss.DataValidation].(map[string][]string); got[FormValueCode][0] != h.ab.Localizef(context.Background(), authboss.TxtInvalid2FACode) {
|
||||
t.Error("data wrong:", got)
|
||||
}
|
||||
})
|
||||
|
@ -110,7 +110,7 @@ func (e EmailVerify) PostStart(w http.ResponseWriter, r *http.Request) error {
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
RedirectPath: e.Authboss.Config.Paths.TwoFactorEmailAuthNotOK,
|
||||
Success: e.Localize(ctx, authboss.TxtEmailVerifyTriggered),
|
||||
Success: e.Localizef(ctx, authboss.TxtEmailVerifyTriggered),
|
||||
}
|
||||
return e.Authboss.Config.Core.Redirector.Redirect(w, r, ro)
|
||||
}
|
||||
@ -125,7 +125,7 @@ func (e EmailVerify) SendVerifyEmail(ctx context.Context, to, token string) {
|
||||
To: []string{to},
|
||||
From: e.Config.Mail.From,
|
||||
FromName: e.Config.Mail.FromName,
|
||||
Subject: e.Config.Mail.SubjectPrefix + e.Localize(ctx, authboss.TxtEmailVerifySubject),
|
||||
Subject: e.Config.Mail.SubjectPrefix + e.Localizef(ctx, authboss.TxtEmailVerifySubject),
|
||||
}
|
||||
|
||||
logger.Infof("sending add 2fa verification e-mail to: %s", to)
|
||||
@ -168,7 +168,7 @@ func (e EmailVerify) End(w http.ResponseWriter, r *http.Request) error {
|
||||
if 1 != subtle.ConstantTimeCompare([]byte(wantToken), []byte(givenToken)) {
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: e.Localize(r.Context(), authboss.TxtInvalid2FAVerificationToken),
|
||||
Failure: e.Localizef(r.Context(), authboss.TxtInvalid2FAVerificationToken),
|
||||
RedirectPath: e.Authboss.Config.Paths.TwoFactorEmailAuthNotOK,
|
||||
}
|
||||
return e.Authboss.Core.Redirector.Redirect(w, r, ro)
|
||||
@ -203,7 +203,7 @@ func (e EmailVerify) Wrap(handler http.Handler) http.Handler {
|
||||
redirURL := path.Join(e.Authboss.Config.Paths.Mount, "2fa", e.TwofactorKind, "email/verify")
|
||||
ro := authboss.RedirectOptions{
|
||||
Code: http.StatusTemporaryRedirect,
|
||||
Failure: e.Localize(r.Context(), authboss.Txt2FAAuthorizationRequired),
|
||||
Failure: e.Localizef(r.Context(), authboss.Txt2FAAuthorizationRequired),
|
||||
RedirectPath: redirURL,
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ func TestEmailVerifyPostStart(t *testing.T) {
|
||||
t.Error("code wrong:", ro.Code)
|
||||
}
|
||||
|
||||
if ro.Success != h.ab.Localize(context.Background(), authboss.TxtEmailVerifyTriggered) {
|
||||
if ro.Success != h.ab.Localizef(context.Background(), authboss.TxtEmailVerifyTriggered) {
|
||||
t.Error("message was wrong:", ro.Success)
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ func TestEmailVerifyEndFail(t *testing.T) {
|
||||
t.Error("redir path wrong:", ro.RedirectPath)
|
||||
}
|
||||
|
||||
if ro.Failure != h.ab.Localize(context.Background(), authboss.TxtInvalid2FAVerificationToken) {
|
||||
if ro.Failure != h.ab.Localizef(context.Background(), authboss.TxtInvalid2FAVerificationToken) {
|
||||
t.Error("did not get correct failure")
|
||||
}
|
||||
|
||||
@ -317,7 +317,7 @@ func TestEmailVerifyWrap(t *testing.T) {
|
||||
t.Error("redir path wrong:", ro.RedirectPath)
|
||||
}
|
||||
|
||||
if ro.Failure != h.ab.Localize(context.Background(), authboss.Txt2FAAuthorizationRequired) {
|
||||
if ro.Failure != h.ab.Localizef(context.Background(), authboss.Txt2FAAuthorizationRequired) {
|
||||
t.Error("did not get correct failure")
|
||||
}
|
||||
})
|
||||
|
@ -159,7 +159,7 @@ func (r *Recover) SendRecoverEmail(ctx context.Context, to []string, encodedToke
|
||||
To: to,
|
||||
From: r.Authboss.Config.Mail.From,
|
||||
FromName: r.Authboss.Config.Mail.FromName,
|
||||
Subject: r.Authboss.Config.Mail.SubjectPrefix + r.Localize(ctx, authboss.TxtPasswordResetEmailSubject),
|
||||
Subject: r.Authboss.Config.Mail.SubjectPrefix + r.Localizef(ctx, authboss.TxtPasswordResetEmailSubject),
|
||||
}
|
||||
|
||||
ro := authboss.EmailResponseOptions{
|
||||
@ -285,7 +285,7 @@ func (r *Recover) EndPost(w http.ResponseWriter, req *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
successMsg := r.Localize(req.Context(), authboss.TxtRecoverSuccessMsg)
|
||||
successMsg := r.Localizef(req.Context(), authboss.TxtRecoverSuccessMsg)
|
||||
if r.Authboss.Config.Modules.RecoverLoginAfterRecovery {
|
||||
handled, err = r.Events.FireBefore(authboss.EventAuth, w, req)
|
||||
if err != nil {
|
||||
@ -302,7 +302,7 @@ func (r *Recover) EndPost(w http.ResponseWriter, req *http.Request) error {
|
||||
}
|
||||
|
||||
authboss.PutSession(w, authboss.SessionKey, user.GetPID())
|
||||
successMsg = r.Localize(req.Context(), authboss.TxtRecoverAndLoginSuccessMsg)
|
||||
successMsg = r.Localizef(req.Context(), authboss.TxtRecoverAndLoginSuccessMsg)
|
||||
|
||||
handled, err = r.Authboss.Events.FireAfter(authboss.EventAuth, w, req)
|
||||
if err != nil {
|
||||
|
@ -278,7 +278,7 @@ func TestRegisterPostUserExists(t *testing.T) {
|
||||
}
|
||||
|
||||
errList := h.responder.Data[authboss.DataValidation].(map[string][]string)
|
||||
if e := errList[""][0]; e != h.ab.Localize(context.Background(), authboss.TxtUserAlreadyExists) {
|
||||
if e := errList[""][0]; e != h.ab.Localizef(context.Background(), authboss.TxtUserAlreadyExists) {
|
||||
t.Error("validation error wrong:", e)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user