@ -2,14 +2,37 @@
< div
class = "csc-input-password-retype"
>
< q -tooltip v-if ="messages.length > 0" >
< div class = "tooltip-message q-pa-md text-body2" >
Password requirements :
< q -item
v - for = "(message, index) in messages"
: key = "index"
dense
>
< q -item -section >
< span >
< q -icon
name = "lock"
size = "1em"
class = "q-pa-xs"
/ > { { m e s s a g e } }
< / span >
< / q - i t e m - s e c t i o n >
< / q - i t e m >
< / div >
< / q - t o o l t i p >
< csc -input -password
ref = "password"
v - model = "password"
v - bind = "$attrs"
generate
clearable
: error = "v$.password.$errors.length > 0"
: error - message = "$errMsg(v$.password.$errors)"
: label = "passwordLabel"
@ update : model - value = "inputPassword"
@ blur = "v$.password.$touch()"
@ generated = "passwordGenerated"
@ clear = "passwordClear"
/ >
@ -29,9 +52,9 @@
v - bind = "$attrs"
: label = "passwordConfirmLabel"
: error = "v$.passwordRetype.$errors.length > 0"
: error - message = " errorMessagePasswordRetype "
: error - message = " $errMsg(v$.passwordRetype.$errors) "
clearable
: disable = " passwordScore < 2 || $attrs.disable"
: disable = " $attrs.disable"
@ clear = "v$.passwordRetype.$reset()"
@ blur = "passwordRetypeBlur"
@ update : model - value = "inputRetypePassword"
@ -39,13 +62,12 @@
< / div >
< / template >
< script >
import {
sameAs ,
required
} from '@vuelidate/validators'
import CscInputPassword from 'components/form/CscInputPassword'
import PasswordMeter from 'vue-simple-password-meter'
import useValidate from '@vuelidate/core'
import { sameAs , required , maxLength , minLength } from '@vuelidate/validators'
import { mapGetters } from 'vuex'
export default {
name : 'CscInputPasswordRetype' ,
components : {
@ -75,6 +97,12 @@ export default {
/ / e s l i n t - d i s a b l e - n e x t - l i n e v u e / n o - d e p r e c a t e d - p r o p s - d e f a u l t - t h i s
return this . $t ( 'Password Retype' )
}
} ,
passwordType : {
type : String ,
default ( ) {
return 'web'
}
}
} ,
emits : [ 'validation-failed' , 'validation-succeeded' , 'update:modelValue' , 'score' ] ,
@ -83,14 +111,13 @@ export default {
password : this . modelValue . password ,
passwordRetype : this . modelValue . passwordRetype ,
passwordScore : null ,
v$ : useValidate ( )
v$ : useValidate ( ) ,
messages : [ ]
}
} ,
validations ( ) {
return {
password : {
required
} ,
password : { ... this . getPasswordValidations ( ) } ,
passwordRetype : {
required ,
sameAsPassword : sameAs ( this . password )
@ -98,13 +125,11 @@ export default {
}
} ,
computed : {
errorMessagePasswordRetype ( ) {
const errorsTab = this . v$ . passwordRetype . $errors
if ( errorsTab && errorsTab . length > 0 && errorsTab [ 0 ] . $validator === 'sameAsPassword' ) {
return this . $t ( 'Passwords must be equal' )
} else {
return ''
}
... mapGetters ( 'user' , [
'passwordRequirements'
] ) ,
areValidationsActive ( ) {
return this . passwordType === 'web' ? this . passwordRequirements . web _validate : this . passwordRequirements . sip _validate
} ,
passwordScoreMappedValue ( ) {
if ( this . passwordScore === null || this . passwordScore === undefined ) {
@ -138,12 +163,66 @@ export default {
this . v$ . $reset ( )
this . $refs . passwordRetype . clear ( )
this . $refs . password . clear ( )
this . messages = this . getPasswordRequirementsMessages ( )
} ,
methods : {
strengthMeterScoreUpdate ( evt ) {
this . passwordScore = evt . score
this . $emit ( 'score' , evt . score )
} ,
getPasswordRequirementsMessages ( ) {
if ( ! this . areValidationsActive ) {
return [ ]
}
const lengthMessage = this . passwordRequirements . minLength > 0
? ` must be between ${ this . passwordRequirements . min _length } and ${ this . passwordRequirements . max _length } characters long `
: null
const digitsMessage = this . passwordRequirements . musthave _digit > 0
? ` must contain at least ${ this . passwordRequirements . musthave _digit } digits `
: null
const lowercaseMessage = this . passwordRequirements . musthave _lowercase > 0
? ` must contain at least ${ this . passwordRequirements . musthave _lowercase } lowercase `
: null
const uppercaseReq = this . passwordRequirements . musthave _uppercase > 0
? ` must contain at least ${ this . passwordRequirements . musthave _uppercase } uppercase `
: null
const specialCharReq = this . passwordRequirements . musthave _specialchar > 0
? ` must contain at least ${ this . passwordRequirements . musthave _specialchar } special characters `
: null
return [ lengthMessage , digitsMessage , lowercaseMessage , uppercaseReq , specialCharReq ] . filter ( ( message ) => message !== null )
} ,
getPasswordValidations ( ) {
if ( this . areValidationsActive ) {
return {
required ,
passwordMaxLength : maxLength ( this . passwordRequirements . max _length ) ,
passwordMinLength : minLength ( this . passwordRequirements . min _length ) ,
passwordDigits ( ) {
const digitPattern = /\d/g
return ( this . password . match ( digitPattern ) || [ ] ) . length >= this . passwordRequirements . musthave _digit
} ,
passwordLowercase ( ) {
const lowercasePattern = /[a-z]/g
return ( this . password . match ( lowercasePattern ) || [ ] ) . length >= this . passwordRequirements . musthave _lowercase
} ,
passwordUppercase ( ) {
const uppercasePattern = /[A-Z]/g
return ( this . password . match ( uppercasePattern ) || [ ] ) . length >= this . passwordRequirements . musthave _uppercase
} ,
passwordChars ( ) {
const specialCharPattern = /[\W_]/g
return ( this . password . match ( specialCharPattern ) || [ ] ) . length >= this . passwordRequirements . musthave _specialchar
} ,
passwordStrength ( ) {
return this . passwordScore >= 2
}
}
}
return { required }
} ,
inputPassword ( ) {
this . $emit ( 'update:modelValue' , {
password : this . password ,
@ -151,7 +230,6 @@ export default {
} )
} ,
inputRetypePassword ( ) {
this . validate ( )
this . inputPassword ( )
} ,
passwordGenerated ( password ) {