From c5161b880f112062ed4f881606c07371acac64f0 Mon Sep 17 00:00:00 2001 From: Bubka <858858+Bubka@users.noreply.github.com> Date: Mon, 6 Jan 2020 17:23:54 +0100 Subject: [PATCH] Error handling and validation during registration --- resources/js/views/Register.vue | 47 ++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/resources/js/views/Register.vue b/resources/js/views/Register.vue index 2802599c..19812d71 100644 --- a/resources/js/views/Register.vue +++ b/resources/js/views/Register.vue @@ -7,26 +7,30 @@
- +
+

Field required

- +
+

Field required

- +
+

Field required

- +
+

Field required

@@ -34,6 +38,10 @@
+
+ + {{ errorMessage }} + @@ -43,16 +51,30 @@ export default { data(){ return { - name : "", - email : "", - password : "", - password_confirmation : "" + name : '', + nameMissing : false, + email : '', + emailMissing : false, + password : '', + passwordMissing : false, + password_confirmation : '', + passwordConfirmationMissing : false, + errorMessage : '', } }, methods : { handleSubmit(e) { e.preventDefault() + this.nameMissing = (this.name.length === 0) ? true : false; + this.emailMissing = (this.email.length === 0) ? true : false; + this.passwordMissing = (this.password.length === 0) ? true : false; + this.passwordConfirmationMissing = (this.password_confirmation.length === 0) ? true : false; + + if( this.nameMissing || this.emailMissing || this.passwordMissing || this.passwordConfirmationMissing ) { + return false; + } + if (this.password === this.password_confirmation && this.password.length > 0) { axios.post('api/register', { @@ -66,17 +88,16 @@ localStorage.setItem('jwt',response.data.success.token) if (localStorage.getItem('jwt') != null){ - this.$router.go('/') + this.$router.push({name: 'accounts'}); } }) .catch(error => { console.error(error); + this.errorMessage = error.message }); } else { - this.password = "" - this.passwordConfirm = "" - - return alert('Passwords do not match') + this.errorMessage = 'Passwords do not match' + return false; } } },