Skip to content

Commit

Permalink
fix: password error message not displayed if policy doesnt exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ayZagen committed Jun 9, 2020
1 parent 634a8c2 commit df20b31
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
22 changes: 16 additions & 6 deletions src/ui/components/PasswordStrength.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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]]
Expand All @@ -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)
}
})
4 changes: 3 additions & 1 deletion src/ui/views/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion src/ui/views/ResetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit df20b31

Please sign in to comment.