Skip to content

Commit

Permalink
Added missing translations
Browse files Browse the repository at this point in the history
  • Loading branch information
svera committed Apr 17, 2024
1 parent d4fb94f commit 0e1267b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions internal/webserver/controller/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package user
import (
"fmt"
"strconv"
"strings"

"github.com/gofiber/fiber/v2"
"github.com/google/uuid"
Expand All @@ -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,
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion internal/webserver/controller/user/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package user
import (
"log"
"strconv"
"strings"

"github.com/gofiber/fiber/v2"
"github.com/svera/coreander/v3/internal/webserver/model"
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/webserver/embedded/translations/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ."
4 changes: 4 additions & 0 deletions internal/webserver/embedded/translations/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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é"
2 changes: 1 addition & 1 deletion internal/webserver/embedded/views/users/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="mb-3">
<label for="username" class="form-label">{{t .Lang "Username"}}</label>
<input type="text" name="username" class='form-control {{if ne (index .Errors "username") ""}}is-invalid{{end}}' id="username" required="required" value="{{.User.Username}}" minlength="3" maxlength="20" pattern="{{.UsernamePattern}}">
<input type="text" name="username" class='form-control {{if ne (index .Errors "username") ""}}is-invalid{{end}}' id="username" required="required" value="{{.User.Username}}" minlength="3" maxlength="20" pattern="{{.UsernamePattern}}" placeholder={{t .Lang "Only letters, numbers, _, - and . allowed"}}>
{{if ne (index .Errors "username") ""}}
<div class="invalid-feedback">
{{t .Lang .Errors.username}}
Expand Down
4 changes: 2 additions & 2 deletions internal/webserver/user_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 0e1267b

Please sign in to comment.