add password change

This commit is contained in:
axolotle 2023-08-01 16:27:27 +02:00
parent 9f7451a276
commit cbe3a5d641

View file

@ -6,18 +6,27 @@ import * as yup from 'yup'
const { handleSubmit } = useForm({ const { handleSubmit } = useForm({
validationSchema: toTypedSchema( validationSchema: toTypedSchema(
yup.object({ yup.object({
currentPassword: yup.string(), current: yup.string().min(8),
newPassword: yup.string().required().min(8), password: yup.string().required().min(8),
confirmNewPassword: yup confirmPassword: yup
.string() .string()
.oneOf([yup.ref('newPassword')]) .oneOf([yup.ref('password')])
.required(), .required(),
}), }),
), ),
}) })
const onSubmit = handleSubmit((form) => { const onSubmit = handleSubmit(async (form) => {
console.log('SUBMIT user password edit', 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
}
}) })
</script> </script>
@ -31,10 +40,10 @@ const onSubmit = handleSubmit((form) => {
<div class="md:flex"> <div class="md:flex">
<div class="basis-1/2 mb-10 md:mr-10"> <div class="basis-1/2 mb-10 md:mr-10">
<FormField name="currentPassword" :label="$t('current_password')"> <FormField name="current" :label="$t('current_password')">
<TextInput <TextInput
name="currentPassword" name="current"
type="text" type="password"
autocomplete="currrent-password" autocomplete="currrent-password"
class="w-full" class="w-full"
/> />
@ -42,22 +51,19 @@ const onSubmit = handleSubmit((form) => {
</div> </div>
<div class="basis-1/2 md:ml-10"> <div class="basis-1/2 md:ml-10">
<FormField name="newPassword" :label="$t('new_password')" class="mb-3"> <FormField name="password" :label="$t('new_password')" class="mb-3">
<TextInput <TextInput
name="newPassword" name="password"
type="text" type="password"
autocomplete="new-password" autocomplete="new-password"
class="w-full" class="w-full"
/> />
</FormField> </FormField>
<FormField <FormField name="confirmPassword" :label="$t('confirm_new_password')">
name="confirmNewPassword"
:label="$t('confirm_new_password')"
>
<TextInput <TextInput
name="confirmNewPassword" name="confirmPassword"
type="text" type="password"
autocomplete="new-password" autocomplete="new-password"
class="w-full" class="w-full"
/> />