47 lines
2.0 KiB
Vue
47 lines
2.0 KiB
Vue
<script lang="ts" setup>
|
||
import {useAccountStore} from "~/store/account";
|
||
import type {ApiError} from "~/composables/fetch-api";
|
||
import {useNotificationStore} from "~/store/notification";
|
||
|
||
const currentPassword = ref();
|
||
const newPassword = ref();
|
||
const confirmationPassword = ref();
|
||
|
||
function updatePassword() {
|
||
useAccountStore().updatePassword(currentPassword.value, newPassword.value, confirmationPassword.value)
|
||
.then(() => {
|
||
useNotificationStore().pushNotification("success",{message: "Votre mot de passe a bien été modifié."});
|
||
navigateTo("/account");
|
||
})
|
||
.catch((apiError: ApiError) => {
|
||
let details;
|
||
if (apiError.fieldErrors) {
|
||
details = apiError.fieldErrors.map(error => `${error.fields!.join(", ")} ${error.detail}`);
|
||
}
|
||
useNotificationStore().pushNotification("warn",{message: apiError.message, details});
|
||
});
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<section>
|
||
<h1>Modifier mon mot de passe</h1>
|
||
<form class="form" @submit.prevent="updatePassword">
|
||
<label for="currentPassword">Mot de passe actuel</label>
|
||
<input id="currentPassword" v-model="currentPassword" type="password" autocomplete="currentPassword" required>
|
||
<p class="form__help">Votre mot de passe doit fait au moins 8 caractères, et être composé d’au moins une
|
||
majuscule, une minuscule,
|
||
un chiffre de 0 à 9, et un caractère spécial parmi @?!#$&;,:</p>
|
||
<label for="newPassword">Nouveau mot de passe</label>
|
||
<input id="newPassword" v-model="newPassword" type="password" required>
|
||
<label for="confirmationPassword">Confirmation du mot de passe</label>
|
||
<input id="confirmationPassword" v-model="confirmationPassword" type="password" required>
|
||
<div class="button-container">
|
||
<nuxt-link class="button gray button-back" to="/account" aria-label="Retour à la page précédente">❮</nuxt-link>
|
||
<button class="button orange" type="submit">Enregistrer</button>
|
||
</div>
|
||
</form>
|
||
</section>
|
||
</template>
|
||
|