From df20b3103a901c5d4d951a349dde7cd39bf07d2c Mon Sep 17 00:00:00 2001 From: ayazismailhakki Date: Tue, 9 Jun 2020 11:11:56 +0300 Subject: [PATCH] fix: password error message not displayed if policy doesnt exists --- src/ui/components/PasswordStrength.ts | 22 ++++++++++++++++------ src/ui/views/Register.vue | 4 +++- src/ui/views/ResetPassword.vue | 4 +++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ui/components/PasswordStrength.ts b/src/ui/components/PasswordStrength.ts index 2907169..881eef5 100644 --- a/src/ui/components/PasswordStrength.ts +++ b/src/ui/components/PasswordStrength.ts @@ -2,6 +2,8 @@ import { defineComponent, h, inject } from 'vue'; import { Translator, translatorKey } from '../utils/translator'; +import PMessage from './PMessage'; + export default defineComponent({ name: 'PasswordStrengthTooltip', props: { @@ -12,7 +14,17 @@ export default defineComponent({ const context = inject('context') as any return { generatePolicyElements(result: any) { - return Object.keys(context.passwordPolicy).map(( policy ) => { + if(!context.passwordPolicy || typeof result === 'string'){ + return h(PMessage, { + class: 'pa__input-details', + value: result + }) + } + return h('div', { + class: { + 'pa-pw-strength': true + } + }, Object.keys(context.passwordPolicy).map(( policy ) => { const elemText = translator.t( `passwordPolicy.${ policy }`, [context.passwordPolicy[policy]] @@ -30,14 +42,12 @@ export default defineComponent({ elemText ]) }) + ) + } } }, render(){ - return h('div', { - class: { - 'pa-pw-strength': true - } - }, this.generatePolicyElements(this.message)) + return this.generatePolicyElements(this.message) } }) diff --git a/src/ui/views/Register.vue b/src/ui/views/Register.vue index daed213..786a2b1 100644 --- a/src/ui/views/Register.vue +++ b/src/ui/views/Register.vue @@ -171,7 +171,9 @@ export default defineComponent({ autocomplete: 'new-password' }, async validator(fields, value){ - return api.auth.checkPasswordStrength(value, context.passwordPolicy) + return !value ? translator.t('register.errors.passwordRequired') : + api.auth.checkPasswordStrength(value, + context.passwordPolicy || {}) } }, rePassword: { diff --git a/src/ui/views/ResetPassword.vue b/src/ui/views/ResetPassword.vue index f77ec42..88df0f2 100644 --- a/src/ui/views/ResetPassword.vue +++ b/src/ui/views/ResetPassword.vue @@ -142,7 +142,9 @@ export default defineComponent({ autocomplete: 'new-password' }, async validator(fields, value){ - return api.auth.checkPasswordStrength(value, context.passwordPolicy) + return !value ? translator.t('resetPassword.errors.passwordRequired') : + api.auth.checkPasswordStrength(value, + context.passwordPolicy || {}) } }, rePassword: {