From 36a82a643e9d8f254f880c1fe1d25ae7175dea8c Mon Sep 17 00:00:00 2001 From: Alexis <35.alexis.pele@gmail.com> Date: Sat, 26 Dec 2020 17:07:09 +0100 Subject: [PATCH] Added comments explaining the changes --- client/src/pages/user/login-page.vue | 13 +++++++++---- client/src/pages/user/register-page.vue | 14 ++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/client/src/pages/user/login-page.vue b/client/src/pages/user/login-page.vue index e4b9c31..7533ade 100644 --- a/client/src/pages/user/login-page.vue +++ b/client/src/pages/user/login-page.vue @@ -116,14 +116,18 @@ export default { this.submitted = true; let userInput = { - "mail": this.email, - "password": this.password + "user": { + "mail": this.email, + "password": this.password, + }, + "remember_me": this.remember_me }; - if (!userInput.mail) { + // Check is all inputs are set + if (!userInput.user.mail) { this.errors.email = "Vous devez renseigner une addresse mail." } - if (!userInput.password) { + if (!userInput.user.password) { this.errors.password = "Vous devez renseigner un mot de passe." } @@ -134,6 +138,7 @@ export default { } } + // If no errors are present, submits the form if (this.submitted) { this.$store.dispatch('user_login', userInput) .then(() => { diff --git a/client/src/pages/user/register-page.vue b/client/src/pages/user/register-page.vue index 83b8b8e..889c128 100644 --- a/client/src/pages/user/register-page.vue +++ b/client/src/pages/user/register-page.vue @@ -148,23 +148,23 @@ export default { this.submitted = true; let userInput = { - "name": this.name, - "mail": this.email, - "password": this.password + "user": { + "name": this.name, + "mail": this.email, + "password": this.password + } } + // Check if all inputs are valid without sending anything if (!userInput.name) { this.errors.name = "Vous devez renseigner un pseudonyme." } - if (!userInput.mail) { this.errors.email = "Vous devez renseigner une addresse mail." } - if (!userInput.password) { this.errors.password = "Vous devez renseigner un mot de passe." } - if ((userInput.password.localeCompare(this.password_check)) != 0) { this.errors.password_check = "Les mots de passe ne correspondent pas." } @@ -176,12 +176,14 @@ export default { } } + // If no errors are present, submits the form if (this.submitted) { this.$store.dispatch('user_register', userInput) .then(() => { this.$router.push('/'); }) .catch(err => { + // Sets errors in case something wrong comes back from the API if (err.status === 409) { this.errors.email = err.data.error; } else {