Skip to content

Commit

Permalink
Merge pull request #87 from svera/fix-send-email-on-creating
Browse files Browse the repository at this point in the history
  • Loading branch information
svera authored May 12, 2024
2 parents f7c1357 + 299a1e7 commit d59b6d5
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
13 changes: 7 additions & 6 deletions internal/webserver/controller/user/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
func (u *Controller) Create(c *fiber.Ctx) error {
role, _ := strconv.Atoi(c.FormValue("role"))
user := model.User{
Name: c.FormValue("name"),
Username: strings.ToLower(c.FormValue("username")),
Email: c.FormValue("email"),
Password: c.FormValue("password"),
Role: role,
Uuid: uuid.NewString(),
Name: c.FormValue("name"),
Username: strings.ToLower(c.FormValue("username")),
Email: c.FormValue("email"),
SendToEmail: c.FormValue("send-to-email"),
Password: c.FormValue("password"),
Role: role,
Uuid: uuid.NewString(),
}
user.WordsPerMinute, _ = strconv.ParseFloat(c.FormValue("words-per-minute"), 64)

Expand Down
4 changes: 4 additions & 0 deletions internal/webserver/embedded/css/reader.css
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,7 @@ body {
fill: Canvas;
filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .2));
}
.spinner {
fill: #888;
stroke: #888;
}
1 change: 1 addition & 0 deletions internal/webserver/embedded/translations/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Edit user": "Editar usuario"
"Name cannot be empty": "Debes introducir un nombre"
"Incorrect email address": "Dirección de correo electrónico incorrecta"
"Incorrect send to email address": "Dirección de correo electrónico de envío incorrecta"
"Incorrect reading speed": "Velocidad de lectura incorrecta"
"A user with this email address already exist": "Ya existe un usuario con esta dirección de correo electrónico"
"Incorrect role": "Rol incorrecto"
Expand Down
1 change: 1 addition & 0 deletions internal/webserver/embedded/translations/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"Edit user": "Modifier l'utilisateur"
"Name cannot be empty": "Le nom ne peut pas être vide"
"Incorrect email address": "Adresse e-mail incorrecte"
"Incorrect send to email address": "Adresse e-mail d'envoi incorrecte"
"Incorrect reading speed": "Vitesse de lecture incorrecte"
"A user with this email address already exist": "Un utilisateur avec cette adresse e-mail existe déjà"
"Incorrect role": "Rôle incorrect"
Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/embedded/views/reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<div id="spinner-container" class="filter">
<div>
<svg width="96" height="96" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_P7sC{transform-origin:center;animation:spinner_svv2 .75s infinite linear}@keyframes spinner_svv2{100%{transform:rotate(360deg)}}</style><path d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z" class="spinner_P7sC"/></svg>
<svg width="96" height="96" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner{transform-origin:center;animation:spinner_svv2 .75s infinite linear}@keyframes spinner_svv2{100%{transform:rotate(360deg)}}</style><path d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z" class="spinner"/></svg>
</div>
</div>

Expand Down
37 changes: 19 additions & 18 deletions internal/webserver/user_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestUserManagement(t *testing.T) {
)

reset := func() {
t.Helper()

var err error
db = infrastructure.Connect("file::memory:", 250)
app = bootstrapApp(db, &infrastructure.NoEmail{}, afero.NewMemMapFs(), webserver.Config{})
Expand Down Expand Up @@ -65,10 +67,8 @@ func TestUserManagement(t *testing.T) {
}
}

reset()

t.Run("Try to add a user without an active session", func(t *testing.T) {
t.Cleanup(reset)
reset()

response, err := getRequest(&http.Cookie{}, app, "/en/users/new", t)
if response == nil {
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to add a user with an admin active session", func(t *testing.T) {
t.Cleanup(reset)
reset()

response, err := getRequest(adminCookie, app, "/en/users/new", t)
if response == nil {
Expand All @@ -109,6 +109,7 @@ func TestUserManagement(t *testing.T) {
"name": {"New user"},
"username": {"new"},
"email": {"new@example.com"},
"send-to-email": {"send@example.com"},
"password": {"new"},
"confirm-password": {"new"},
"role": {fmt.Sprint(model.RoleRegular)},
Expand All @@ -130,7 +131,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to add a user with a regular user active session", func(t *testing.T) {
t.Cleanup(reset)
reset()

response, err := getRequest(regularUserCookie, app, "/en/users/new", t)
if response == nil {
Expand All @@ -148,7 +149,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to add a user with errors in form", func(t *testing.T) {
t.Cleanup(reset)
reset()

response, err := postRequest(url.Values{}, adminCookie, app, "/en/users/new", t)
expectedErrorMessages := []string{
Expand All @@ -167,7 +168,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to add a user with already registered email and username", func(t *testing.T) {
t.Cleanup(reset)
reset()

newUserData := url.Values{
"name": {"Test user"},
Expand All @@ -192,7 +193,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to update a user without an active session", func(t *testing.T) {
t.Cleanup(reset)
reset()

response, err := getRequest(&http.Cookie{}, app, fmt.Sprintf("/en/users/%s/edit", regularUser.Username), t)
if response == nil {
Expand All @@ -210,7 +211,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to update a user using another, non admin user session", func(t *testing.T) {
t.Cleanup(reset)
reset()

adminUserData := regularUserData
adminUserData.Set("id", adminUser.Uuid)
Expand All @@ -231,7 +232,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to update the user in session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData.Set("name", "Updated regular user")
regularUserData.Set("id", regularUser.Uuid)
Expand All @@ -255,7 +256,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to update a user with an admin session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData.Set("name", "Updated regular user by an admin")
regularUserData.Set("id", regularUser.Uuid)
Expand All @@ -279,7 +280,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to edit a non existing user with an admin session", func(t *testing.T) {
t.Cleanup(reset)
reset()

response, err := getRequest(adminCookie, app, fmt.Sprintf("/en/users/%s/edit", "abcde"), t)
if response == nil {
Expand All @@ -289,7 +290,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to update a non existing user with an admin session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData.Set("name", "Updated test user by an admin")

Expand All @@ -301,7 +302,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to delete a user without an active session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData = url.Values{
"id": {regularUser.Uuid},
Expand All @@ -316,7 +317,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to delete a user with a regular user's session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData = url.Values{
"id": {regularUser.Uuid},
Expand All @@ -333,7 +334,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to delete a user with an admin session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData = url.Values{
"id": {regularUser.Uuid},
Expand All @@ -352,7 +353,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to delete the only existing admin user", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData = url.Values{
"id": {adminUser.Uuid},
Expand All @@ -366,7 +367,7 @@ func TestUserManagement(t *testing.T) {
})

t.Run("Try to delete a non existing user with an admin session", func(t *testing.T) {
t.Cleanup(reset)
reset()

regularUserData = url.Values{
"id": {"abcde"},
Expand Down

0 comments on commit d59b6d5

Please sign in to comment.