2023-07-26 05:19:52 +02:00
|
|
|
<script setup lang="ts">
|
2023-07-27 17:54:29 +02:00
|
|
|
import { useForm } from 'vee-validate'
|
|
|
|
import { toTypedSchema } from '@vee-validate/yup'
|
2023-07-26 05:19:52 +02:00
|
|
|
import * as yup from 'yup'
|
|
|
|
|
2023-07-27 17:54:29 +02:00
|
|
|
const { handleSubmit } = useForm({
|
|
|
|
validationSchema: toTypedSchema(
|
|
|
|
yup.object({
|
2023-08-01 16:27:27 +02:00
|
|
|
current: yup.string().min(8),
|
|
|
|
password: yup.string().required().min(8),
|
|
|
|
confirmPassword: yup
|
2023-07-27 17:54:29 +02:00
|
|
|
.string()
|
2023-08-01 16:27:27 +02:00
|
|
|
.oneOf([yup.ref('password')])
|
2023-07-27 17:54:29 +02:00
|
|
|
.required(),
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
})
|
2023-07-26 05:19:52 +02:00
|
|
|
|
2023-08-01 16:27:27 +02:00
|
|
|
const onSubmit = handleSubmit(async (form) => {
|
|
|
|
const { error } = await useApi('/me/update_password', {
|
|
|
|
method: 'PUT',
|
|
|
|
body: { current: form.current, password: form.password },
|
|
|
|
})
|
|
|
|
if (!error.value) {
|
|
|
|
useIsLoggedIn().value = false
|
|
|
|
navigateTo('/login')
|
|
|
|
} else {
|
|
|
|
// FIXME display generic error
|
|
|
|
}
|
2023-07-27 17:54:29 +02:00
|
|
|
})
|
2023-07-26 05:19:52 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-07-27 17:54:29 +02:00
|
|
|
<form novalidate @submit="onSubmit">
|
2023-07-26 05:19:52 +02:00
|
|
|
<!-- FIXME replace with accessible component -->
|
|
|
|
<div role="alert" class="alert alert-warning mb-10">
|
|
|
|
<Icon name="mdi:warning-outline" size="2em" />
|
|
|
|
{{ $t('good_practices_about_user_password') }}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="md:flex">
|
|
|
|
<div class="basis-1/2 mb-10 md:mr-10">
|
2023-08-01 16:27:27 +02:00
|
|
|
<FormField name="current" :label="$t('current_password')">
|
2023-07-27 17:54:29 +02:00
|
|
|
<TextInput
|
2023-08-01 16:27:27 +02:00
|
|
|
name="current"
|
|
|
|
type="password"
|
2023-07-27 17:54:29 +02:00
|
|
|
autocomplete="currrent-password"
|
|
|
|
class="w-full"
|
|
|
|
/>
|
2023-07-26 05:19:52 +02:00
|
|
|
</FormField>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="basis-1/2 md:ml-10">
|
2023-08-01 16:27:27 +02:00
|
|
|
<FormField name="password" :label="$t('new_password')" class="mb-3">
|
2023-07-27 17:54:29 +02:00
|
|
|
<TextInput
|
2023-08-01 16:27:27 +02:00
|
|
|
name="password"
|
|
|
|
type="password"
|
2023-07-27 17:54:29 +02:00
|
|
|
autocomplete="new-password"
|
|
|
|
class="w-full"
|
|
|
|
/>
|
2023-07-26 05:19:52 +02:00
|
|
|
</FormField>
|
|
|
|
|
2023-08-01 16:27:27 +02:00
|
|
|
<FormField name="confirmPassword" :label="$t('confirm_new_password')">
|
2023-07-27 17:54:29 +02:00
|
|
|
<TextInput
|
2023-08-01 16:27:27 +02:00
|
|
|
name="confirmPassword"
|
|
|
|
type="password"
|
2023-07-27 17:54:29 +02:00
|
|
|
autocomplete="new-password"
|
|
|
|
class="w-full"
|
|
|
|
/>
|
2023-07-26 05:19:52 +02:00
|
|
|
</FormField>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex mt-10">
|
|
|
|
<NuxtLink to="/" class="btn ml-auto mr-2">
|
|
|
|
{{ $t('cancel') }}
|
|
|
|
</NuxtLink>
|
|
|
|
<YButton :text="$t('ok')" type="submit" variant="success" />
|
|
|
|
</div>
|
2023-07-27 17:54:29 +02:00
|
|
|
</form>
|
2023-07-26 05:19:52 +02:00
|
|
|
</template>
|