From 70da8e0d38be1ea90edc33784e94a8d5435f8ac5 Mon Sep 17 00:00:00 2001 From: Jonathan Cobb Date: Thu, 12 Mar 2020 15:20:43 -0400 Subject: [PATCH] validate confirm password on registration page. fix registration error display. --- src/_helpers/util.js | 6 +++++- src/_services/user.service.js | 20 ++++++++++---------- src/auth/RegisterPage.vue | 21 ++++++++++++++++----- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/_helpers/util.js b/src/_helpers/util.js index 6d1ff3e..4a0e68b 100644 --- a/src/_helpers/util.js +++ b/src/_helpers/util.js @@ -177,7 +177,11 @@ export const util = { const field = parts[1]; const message = messages[messageTemplate]; const err = {field: field, msg: message}; - if (typeof errors !== 'undefined') errors.add(err); + if (typeof errors !== 'undefined') { + errors.add(err); + } else { + // console.log('setValidationErrors: errors is undefined, not adding: '+JSON.stringify(err)); + } if (messageTemplate === 'err_logout_noSession') { console.log('setValidationErrors: detected err_logout_noSession, logging out'); util.logout(); diff --git a/src/_services/user.service.js b/src/_services/user.service.js index c6c91d8..05c9509 100644 --- a/src/_services/user.service.js +++ b/src/_services/user.service.js @@ -202,24 +202,24 @@ function handleAuthResponse(messages, errors) { console.log('handleAuthResponse: received 404, user not found: '+JSON.stringify(data)); } else if (response.status === 422) { - console.log('handleAuthResponse: received 422: '+JSON.stringify(data)); - const errors = util.setValidationErrors(data, messages, errors, false); - console.log('handleAuthResponse: received errors: '+JSON.stringify(errors)); - if (errors !== null && errors.length > 0) { - const totpInvalidError = errors.indexOf('err_totpToken_invalid'); + // console.log('handleAuthResponse: received 422: '+JSON.stringify(data)); + const errs = util.setValidationErrors(data, messages, errors, false); + // console.log('handleAuthResponse: received errors: '+JSON.stringify(errors)); + if (errs !== null && errs.length > 0) { + const totpInvalidError = errs.indexOf('err_totpToken_invalid'); if (totpInvalidError !== -1) { console.log('handleAuthResponse: rejecting with totpInvalid'); - return Promise.reject(errors[totpInvalidError]); + return Promise.reject(errs[totpInvalidError]); } - const totpRequiredError = errors.indexOf('err_totpToken_required'); + const totpRequiredError = errs.indexOf('err_totpToken_required'); if (totpRequiredError !== -1) { console.log('handleAuthResponse: rejecting with totpRequired'); - return Promise.reject(errors[totpRequiredError]); + return Promise.reject(errs[totpRequiredError]); } } - console.log('handleAuthResponse: plain old rejecting with errors: '+JSON.stringify(errors)); - return Promise.reject(errors); + // console.log('handleAuthResponse: plain old rejecting with errors: '+JSON.stringify(errs)); + return Promise.reject(errs); } const error = (data && data.message) || response.statusText; return Promise.reject(error); diff --git a/src/auth/RegisterPage.vue b/src/auth/RegisterPage.vue index 6d603f5..edcc69b 100644 --- a/src/auth/RegisterPage.vue +++ b/src/auth/RegisterPage.vue @@ -6,22 +6,27 @@
-
{{ errors.first('name') }}
+
{{ errors.first('name') }}
-
{{ errors.first('password') }}
+
{{ errors.first('password') }}
+
+
+ + +
{{ errors.first('confirmPassword') }}
-
{{ errors.first('email') }}
+
{{ errors.first('email') }}
-
{{ errors.first('promoCode') }}
+
{{ errors.first('promoCode') }}
@@ -63,6 +68,7 @@ export default { agreeToTerms: null, promoCode: null }, + confirmPassword: '', submitted: false } }, @@ -74,10 +80,15 @@ export default { ...mapActions('account', ['register']), ...mapGetters('system', ['promoCodesEnabled', 'promoCodeRequired']), handleSubmit(e) { + this.errors.clear(); this.submitted = true; this.$validator.validate().then(valid => { if (valid) { - this.register({user: this.user, messages: this.messages, errors: this.errors}); + if (this.user.password !== this.confirmPassword) { + this.errors.add({field: 'confirmPassword', msg: this.messages['err_confirmPassword_mismatch']}) + } else { + this.register({user: this.user, messages: this.messages, errors: this.errors}); + } } }); }