fix(password): validate password before sending request to api
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
kolaente 2024-09-10 17:44:52 +02:00
parent 1085a6583b
commit eb95caf757
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 20 additions and 17 deletions

@ -36,6 +36,7 @@ import {ref, watchEffect} from 'vue'
import {useDebounceFn} from '@vueuse/core'
import {useI18n} from 'vue-i18n'
import BaseButton from '@/components/base/BaseButton.vue'
import {validatePassword} from '@/helpers/validatePasswort';
const props = withDefaults(defineProps<{
modelValue: string,
@ -60,22 +61,8 @@ const validateAfterFirst = ref(false)
watchEffect(() => props.validateInitially && validate())
const validate = useDebounceFn(() => {
if (password.value === '') {
isValid.value = t('user.auth.passwordRequired')
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
const valid = validatePassword(password.value, props.validateMinLength)
isValid.value = valid === true ? true : t(valid)
}, 100)
function togglePasswordFieldType() {

@ -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 {useConfigStore} from '@/stores/config'
import {validatePassword} from '@/helpers/validatePasswort'
const {t} = useI18n()
const authStore = useAuthStore()
@ -183,7 +184,7 @@ const validateUsername = useDebounceFn(() => {
const everythingValid = computed(() => {
return credentials.username !== '' &&
credentials.email !== '' &&
credentials.password !== '' &&
validatePassword(credentials.password) === true &&
emailValid.value &&
usernameValid.value
})