fix(password): validate password before sending request to api
(cherry picked from commit eb95caf757c05f61d8bc705df62e595903e509d5)
This commit is contained in:
parent
01a7a62541
commit
10edeafa46
@ -36,6 +36,7 @@ import {ref, watchEffect} from 'vue'
|
|||||||
import {useDebounceFn} from '@vueuse/core'
|
import {useDebounceFn} from '@vueuse/core'
|
||||||
import {useI18n} from 'vue-i18n'
|
import {useI18n} from 'vue-i18n'
|
||||||
import BaseButton from '@/components/base/BaseButton.vue'
|
import BaseButton from '@/components/base/BaseButton.vue'
|
||||||
|
import {validatePassword} from '@/helpers/validatePasswort';
|
||||||
|
|
||||||
const props = withDefaults(defineProps<{
|
const props = withDefaults(defineProps<{
|
||||||
modelValue: string,
|
modelValue: string,
|
||||||
@ -60,22 +61,8 @@ const validateAfterFirst = ref(false)
|
|||||||
watchEffect(() => props.validateInitially && validate())
|
watchEffect(() => props.validateInitially && validate())
|
||||||
|
|
||||||
const validate = useDebounceFn(() => {
|
const validate = useDebounceFn(() => {
|
||||||
if (password.value === '') {
|
const valid = validatePassword(password.value, props.validateMinLength)
|
||||||
isValid.value = t('user.auth.passwordRequired')
|
isValid.value = valid === true ? true : t(valid)
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.validateMinLength && password.value.length < 8) {
|
|
||||||
isValid.value = t('user.auth.passwordNotMin')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (props.validateMinLength && password.value.length > 250) {
|
|
||||||
isValid.value = t('user.auth.passwordNotMax')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
isValid.value = true
|
|
||||||
}, 100)
|
}, 100)
|
||||||
|
|
||||||
function togglePasswordFieldType() {
|
function togglePasswordFieldType() {
|
||||||
|
15
frontend/src/helpers/validatePasswort.ts
Normal file
15
frontend/src/helpers/validatePasswort.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
export function validatePassword(password: string, validateMinLength: boolean = true): string | true {
|
||||||
|
if (password === '') {
|
||||||
|
return 'user.auth.passwordRequired'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validateMinLength && password.length < 8) {
|
||||||
|
return 'user.auth.passwordNotMin'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validateMinLength && password.length > 250) {
|
||||||
|
return 'user.auth.passwordNotMax'
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
@ -127,6 +127,7 @@ import Password from '@/components/input/Password.vue'
|
|||||||
|
|
||||||
import {useAuthStore} from '@/stores/auth'
|
import {useAuthStore} from '@/stores/auth'
|
||||||
import {useConfigStore} from '@/stores/config'
|
import {useConfigStore} from '@/stores/config'
|
||||||
|
import {validatePassword} from '@/helpers/validatePasswort'
|
||||||
|
|
||||||
const {t} = useI18n()
|
const {t} = useI18n()
|
||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
@ -183,7 +184,7 @@ const validateUsername = useDebounceFn(() => {
|
|||||||
const everythingValid = computed(() => {
|
const everythingValid = computed(() => {
|
||||||
return credentials.username !== '' &&
|
return credentials.username !== '' &&
|
||||||
credentials.email !== '' &&
|
credentials.email !== '' &&
|
||||||
credentials.password !== '' &&
|
validatePassword(credentials.password) === true &&
|
||||||
emailValid.value &&
|
emailValid.value &&
|
||||||
usernameValid.value
|
usernameValid.value
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user