mirror of
https://github.com/YunoHost/yunohost-portal.git
synced 2024-09-03 20:06:23 +02:00
redirect on password change + rename args
This commit is contained in:
parent
d14071995b
commit
bba01d685b
1 changed files with 34 additions and 32 deletions
|
@ -20,20 +20,20 @@ const { handleSubmit, setFieldError, resetForm, meta } = useForm({
|
||||||
yup.object({
|
yup.object({
|
||||||
// username: yup.string().required(),
|
// username: yup.string().required(),
|
||||||
fullname: yup.string().required().min(2),
|
fullname: yup.string().required().min(2),
|
||||||
currentPassword: yup
|
currentpassword: yup
|
||||||
.string()
|
.string()
|
||||||
.when('newPassword', ([newPassword], schema) => {
|
.when('newpassword', ([newpassword], schema) => {
|
||||||
return newPassword ? schema.required() : schema
|
return newpassword ? schema.required() : schema
|
||||||
}),
|
}),
|
||||||
newPassword: yup.string().matches(/.{8,}/, {
|
newpassword: yup.string().matches(/.{8,}/, {
|
||||||
excludeEmptyString: true,
|
excludeEmptyString: true,
|
||||||
message: { key: 'v.string_too_short', values: { min: 8 } },
|
message: { key: 'v.string_too_short', values: { min: 8 } },
|
||||||
}),
|
}),
|
||||||
confirmNewPassword: yup
|
confirmpassword: yup
|
||||||
.string()
|
.string()
|
||||||
.when('newPassword', ([newPassword], schema) => {
|
.when('newpassword', ([newpassword], schema) => {
|
||||||
return newPassword
|
return newpassword
|
||||||
? schema.oneOf([yup.ref('newPassword')], 'v.password_not_match')
|
? schema.oneOf([yup.ref('newpassword')], 'v.password_not_match')
|
||||||
: schema
|
: schema
|
||||||
}),
|
}),
|
||||||
mailalias: yup.array().of(yup.string().email().required()).required(),
|
mailalias: yup.array().of(yup.string().email().required()).required(),
|
||||||
|
@ -41,15 +41,15 @@ const { handleSubmit, setFieldError, resetForm, meta } = useForm({
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
initialValues: {
|
initialValues: {
|
||||||
currentPassword: '',
|
currentpassword: '',
|
||||||
newPassword: '',
|
newpassword: '',
|
||||||
confirmNewPassword: '',
|
confirmpassword: '',
|
||||||
...pick(userData.value, 'fullname', 'mailalias', 'mailforward'),
|
...pick(userData.value, 'fullname', 'mailalias', 'mailforward'),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => meta.value.touched,
|
() => meta.value.dirty,
|
||||||
(value) => {
|
(value) => {
|
||||||
// remove loading and feedback on edition
|
// remove loading and feedback on edition
|
||||||
if (value) {
|
if (value) {
|
||||||
|
@ -66,10 +66,12 @@ const onSubmit = handleSubmit(async (form) => {
|
||||||
Pick<UserData, 'fullname' | 'mailalias' | 'mailforward'>
|
Pick<UserData, 'fullname' | 'mailalias' | 'mailforward'>
|
||||||
>('/update', {
|
>('/update', {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: exclude(form, 'confirmNewPassword'),
|
body: exclude(form, 'confirmpassword'),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (error.value) {
|
if (error.value) {
|
||||||
|
// Reset form dirty state but keep previous values
|
||||||
|
resetForm({ values: form })
|
||||||
const errData = error.value.data
|
const errData = error.value.data
|
||||||
if (errData.path) {
|
if (errData.path) {
|
||||||
setFieldError(errData.path, errData.error)
|
setFieldError(errData.path, errData.error)
|
||||||
|
@ -77,17 +79,23 @@ const onSubmit = handleSubmit(async (form) => {
|
||||||
feedback.value = {
|
feedback.value = {
|
||||||
variant: 'error',
|
variant: 'error',
|
||||||
icon: 'mdi:alert',
|
icon: 'mdi:alert',
|
||||||
message: errData.error,
|
message: errData.error || errData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (data.value) {
|
} else if (data.value) {
|
||||||
|
// redirect on password change
|
||||||
|
if (form.newpassword) {
|
||||||
|
useIsLoggedIn().value = false
|
||||||
|
return navigateTo('/login')
|
||||||
|
}
|
||||||
|
|
||||||
update(data.value)
|
update(data.value)
|
||||||
resetForm({
|
resetForm({
|
||||||
values: {
|
values: {
|
||||||
...data.value,
|
...data.value,
|
||||||
currentPassword: '',
|
currentpassword: '',
|
||||||
newPassword: '',
|
newpassword: '',
|
||||||
confirmNewPassword: '',
|
confirmpassword: '',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
feedback.value = {
|
feedback.value = {
|
||||||
|
@ -105,8 +113,6 @@ const onSubmit = handleSubmit(async (form) => {
|
||||||
<PageTitle :text="$t('footerlink_edit')" />
|
<PageTitle :text="$t('footerlink_edit')" />
|
||||||
|
|
||||||
<form novalidate class="my-10" @submit="onSubmit">
|
<form novalidate class="my-10" @submit="onSubmit">
|
||||||
<BaseAlert v-show="feedback" v-bind="feedback" class="mb-10" />
|
|
||||||
|
|
||||||
<div class="lg:flex lg:justify-between">
|
<div class="lg:flex lg:justify-between">
|
||||||
<div class="lg:w-1/2 lg:me-20">
|
<div class="lg:w-1/2 lg:me-20">
|
||||||
<!-- <FormField name="username" :label="$t('username')" class="mb-3">
|
<!-- <FormField name="username" :label="$t('username')" class="mb-3">
|
||||||
|
@ -151,12 +157,12 @@ const onSubmit = handleSubmit(async (form) => {
|
||||||
<legend class="text-xl mb-3">{{ $t('change_password') }}</legend>
|
<legend class="text-xl mb-3">{{ $t('change_password') }}</legend>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
name="currentPassword"
|
name="currentpassword"
|
||||||
:label="$t('current_password')"
|
:label="$t('current_password')"
|
||||||
class="mb-3"
|
class="mb-3"
|
||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
name="currentPassword"
|
name="currentpassword"
|
||||||
type="password"
|
type="password"
|
||||||
autocomplete="current-password"
|
autocomplete="current-password"
|
||||||
class="w-full"
|
class="w-full"
|
||||||
|
@ -164,32 +170,28 @@ const onSubmit = handleSubmit(async (form) => {
|
||||||
</FormField>
|
</FormField>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
name="newPassword"
|
name="newpassword"
|
||||||
:label="$t('new_password')"
|
:label="$t('new_password')"
|
||||||
:description="$t('good_practices_about_user_password')"
|
:description="$t('good_practices_about_user_password')"
|
||||||
class="mb-3"
|
class="mb-3"
|
||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
name="newPassword"
|
name="newpassword"
|
||||||
type="password"
|
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"
|
<TextInput name="confirmpassword" type="password" class="w-full" />
|
||||||
:label="$t('confirm_new_password')"
|
|
||||||
>
|
|
||||||
<TextInput
|
|
||||||
name="confirmNewPassword"
|
|
||||||
type="password"
|
|
||||||
class="w-full"
|
|
||||||
/>
|
|
||||||
</FormField>
|
</FormField>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Success + generic error announcement -->
|
||||||
|
<BaseAlert v-show="feedback" v-bind="feedback" class="mb-10" />
|
||||||
|
|
||||||
<!-- SR "loading" announcement -->
|
<!-- SR "loading" announcement -->
|
||||||
<BaseAlert
|
<BaseAlert
|
||||||
:message="loading ? $t('api.processing') : ''"
|
:message="loading ? $t('api.processing') : ''"
|
||||||
|
|
Loading…
Add table
Reference in a new issue