From 0e1267bcbfed03a93bafe666f91f06df05477893 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Wed, 17 Apr 2024 12:22:45 +0200 Subject: [PATCH] Added missing translations --- internal/webserver/controller/user/create.go | 7 ++++--- internal/webserver/controller/user/update.go | 3 ++- internal/webserver/embedded/translations/es.yml | 4 ++++ internal/webserver/embedded/translations/fr.yml | 4 ++++ internal/webserver/embedded/views/users/new.html | 2 +- internal/webserver/user_management_test.go | 4 ++-- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/internal/webserver/controller/user/create.go b/internal/webserver/controller/user/create.go index 5be9c19..ece86b1 100644 --- a/internal/webserver/controller/user/create.go +++ b/internal/webserver/controller/user/create.go @@ -3,6 +3,7 @@ package user import ( "fmt" "strconv" + "strings" "github.com/gofiber/fiber/v2" "github.com/google/uuid" @@ -14,7 +15,7 @@ func (u *Controller) Create(c *fiber.Ctx) error { role, _ := strconv.Atoi(c.FormValue("role")) user := model.User{ Name: c.FormValue("name"), - Username: c.FormValue("username"), + Username: strings.ToLower(c.FormValue("username")), Email: c.FormValue("email"), Password: c.FormValue("password"), Role: role, @@ -24,11 +25,11 @@ func (u *Controller) Create(c *fiber.Ctx) error { errs := user.Validate(u.config.MinPasswordLength) if exist, _ := u.repository.FindByEmail(c.FormValue("email")); exist != nil { - errs["email"] = "A user with this email address already exist" + errs["email"] = "A user with this email address already exists" } if exist, _ := u.repository.FindByUsername(c.FormValue("username")); exist != nil { - errs["username"] = "A user with this username already exist" + errs["username"] = "A user with this username already exists" } if errs = user.ConfirmPassword(c.FormValue("confirm-password"), u.config.MinPasswordLength, errs); len(errs) > 0 { diff --git a/internal/webserver/controller/user/update.go b/internal/webserver/controller/user/update.go index 6c73276..a69f897 100644 --- a/internal/webserver/controller/user/update.go +++ b/internal/webserver/controller/user/update.go @@ -3,6 +3,7 @@ package user import ( "log" "strconv" + "strings" "github.com/gofiber/fiber/v2" "github.com/svera/coreander/v3/internal/webserver/model" @@ -37,7 +38,7 @@ func (u *Controller) Update(c *fiber.Ctx) error { func (u *Controller) updateUserData(user *model.User, c *fiber.Ctx, session model.User) error { user.Name = c.FormValue("name") - user.Username = c.FormValue("username") + user.Username = strings.ToLower(c.FormValue("username")) user.Email = c.FormValue("email") user.SendToEmail = c.FormValue("send-to-email") user.WordsPerMinute, _ = strconv.ParseFloat(c.FormValue("words-per-minute"), 64) diff --git a/internal/webserver/embedded/translations/es.yml b/internal/webserver/embedded/translations/es.yml index 819ea36..ff8c7c4 100644 --- a/internal/webserver/embedded/translations/es.yml +++ b/internal/webserver/embedded/translations/es.yml @@ -119,3 +119,7 @@ "Indexing in progress, search results may not be accurate.": "Indexando documentos, los resultados de búsqueda pueden no ser precisos." "Remaining time: %s minutes": "Tiempo restante: %s minutos" "There was an error deleting the user, please try again later": "Hubo un error al borrar el usuario, por favor, vuelva a intentarlo más tarde" +"A user with this username already exists": "Ya exista un usuario con ese nombre de usuario" +"A user with this email address already exists": "Ya existe un usuario con esa dirección de correo electrónico" +"Username can only have letters, numbers, _, - and .": "El nombre de usuario solo puede contener letras, números. _, - y ." +"Only letters, numbers, _, - and . allowed": "Solo se permiten letras, números, _, - y ." diff --git a/internal/webserver/embedded/translations/fr.yml b/internal/webserver/embedded/translations/fr.yml index ae9fae7..24f467f 100644 --- a/internal/webserver/embedded/translations/fr.yml +++ b/internal/webserver/embedded/translations/fr.yml @@ -119,3 +119,7 @@ "Indexing in progress, search results may not be accurate.": "Indexation en cours, les résultats de la recherche peuvent ne pas être précis." "Remaining time: %s minutes": "Temps restant: %s minutes" "There was an error deleting the user, please try again later": "Une erreur s'est produite lors de supprimer l'utilisateur, veuillez réessayer ultérieurement" +"A user with this username already exists": "Un utilisateur avec ce nom d'utilisateur existe déjà" +"A user with this email address already exists": "Un utilisateur avec cette adresse e-mail existe déjà" +"Username can only have letters, numbers, _, - and .": "Le nom d'utilisateur ne peut contenir que des lettres, des chiffres, _, - et ." +"Only letters, numbers, _, - and . allowed": "Uniquement les lettres, chiffres, _, - et . autorisé" diff --git a/internal/webserver/embedded/views/users/new.html b/internal/webserver/embedded/views/users/new.html index a1da09a..fe2ddd2 100644 --- a/internal/webserver/embedded/views/users/new.html +++ b/internal/webserver/embedded/views/users/new.html @@ -10,7 +10,7 @@
- + {{if ne (index .Errors "username") ""}}
{{t .Lang .Errors.username}} diff --git a/internal/webserver/user_management_test.go b/internal/webserver/user_management_test.go index 468bf3b..18e0503 100644 --- a/internal/webserver/user_management_test.go +++ b/internal/webserver/user_management_test.go @@ -180,8 +180,8 @@ func TestUserManagement(t *testing.T) { response, err := postRequest(newUserData, adminCookie, app, "/en/users/new", t) expectedErrorMessages := []string{ - "A user with this username already exist", - "A user with this email address already exist", + "A user with this username already exists", + "A user with this email address already exists", } if response == nil { t.Fatalf("Unexpected error: %v", err.Error())