Added comments explaining the changes

This commit is contained in:
Alexis
2020-12-26 17:07:09 +01:00
parent 79c34a6ad1
commit 36a82a643e
2 changed files with 17 additions and 10 deletions

View File

@@ -116,14 +116,18 @@ export default {
this.submitted = true; this.submitted = true;
let userInput = { let userInput = {
"mail": this.email, "user": {
"password": this.password "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." 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." 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) { if (this.submitted) {
this.$store.dispatch('user_login', userInput) this.$store.dispatch('user_login', userInput)
.then(() => { .then(() => {

View File

@@ -148,23 +148,23 @@ export default {
this.submitted = true; this.submitted = true;
let userInput = { let userInput = {
"name": this.name, "user": {
"mail": this.email, "name": this.name,
"password": this.password "mail": this.email,
"password": this.password
}
} }
// Check if all inputs are valid without sending anything
if (!userInput.name) { if (!userInput.name) {
this.errors.name = "Vous devez renseigner un pseudonyme." this.errors.name = "Vous devez renseigner un pseudonyme."
} }
if (!userInput.mail) { if (!userInput.mail) {
this.errors.email = "Vous devez renseigner une addresse mail." this.errors.email = "Vous devez renseigner une addresse mail."
} }
if (!userInput.password) { if (!userInput.password) {
this.errors.password = "Vous devez renseigner un mot de passe." this.errors.password = "Vous devez renseigner un mot de passe."
} }
if ((userInput.password.localeCompare(this.password_check)) != 0) { if ((userInput.password.localeCompare(this.password_check)) != 0) {
this.errors.password_check = "Les mots de passe ne correspondent pas." 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) { if (this.submitted) {
this.$store.dispatch('user_register', userInput) this.$store.dispatch('user_register', userInput)
.then(() => { .then(() => {
this.$router.push('/'); this.$router.push('/');
}) })
.catch(err => { .catch(err => {
// Sets errors in case something wrong comes back from the API
if (err.status === 409) { if (err.status === 409) {
this.errors.email = err.data.error; this.errors.email = err.data.error;
} else { } else {