2025-05-02 17:58:50 +02:00
|
|
|
<template>
|
|
|
|
|
<h1>Compte</h1>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>
|
|
|
|
|
<p v-if="user.name">Nom : {{ user.name }}</p>
|
|
|
|
|
</li>
|
2025-05-05 14:01:03 +02:00
|
|
|
<li :class="{ 'is-editing': isEditingEmail }">
|
2025-05-02 17:58:50 +02:00
|
|
|
<input
|
|
|
|
|
v-if="isEditingEmail"
|
|
|
|
|
type="email"
|
|
|
|
|
v-model="email"
|
|
|
|
|
id="username"
|
|
|
|
|
placeholder="mail@exemple.com"
|
|
|
|
|
autocomplete="username"
|
|
|
|
|
class="w-full rounded-md border border-grey-200 px-16 py-12"
|
2025-05-05 16:41:22 +02:00
|
|
|
:class="{ invalid: emailRegex.test(email) }"
|
2025-05-02 17:58:50 +02:00
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
<p v-else>Email : {{ user.email }}</p>
|
2025-05-05 17:23:55 +02:00
|
|
|
<button
|
|
|
|
|
v-if="isEditingEmail"
|
|
|
|
|
class="btn | w-full"
|
|
|
|
|
:class="'btn--' + emailBtn.status"
|
|
|
|
|
>
|
|
|
|
|
{{ emailBtn.text }}
|
|
|
|
|
</button>
|
2025-05-02 17:58:50 +02:00
|
|
|
<button v-else @click="isEditingEmail = true" class="btn | w-full">
|
|
|
|
|
modifier
|
|
|
|
|
</button>
|
|
|
|
|
</li>
|
2025-05-05 16:41:22 +02:00
|
|
|
<li :class="{ 'is-editing': isEditingEmail }">
|
|
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
v-model="password"
|
|
|
|
|
id="password"
|
2025-05-05 16:57:54 +02:00
|
|
|
placeholder="Minimum 8 caractères"
|
2025-05-05 16:41:22 +02:00
|
|
|
class="w-full rounded-md border border-grey-200 px-16 py-12"
|
|
|
|
|
:class="{ invalid: password.length < 8 }"
|
|
|
|
|
required
|
|
|
|
|
/>
|
2025-05-05 16:57:54 +02:00
|
|
|
<input
|
|
|
|
|
type="password"
|
|
|
|
|
v-model="passwordConfirm"
|
|
|
|
|
id="password-confirm"
|
|
|
|
|
placeholder="Minimum 8 caractères"
|
|
|
|
|
class="w-full rounded-md border border-grey-200 px-16 py-12"
|
|
|
|
|
:class="{ invalid: !isPasswordConfirmed }"
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
class="btn | w-full"
|
2025-05-05 17:23:55 +02:00
|
|
|
:class="'btn--' + passwordBtn.status"
|
2025-05-05 16:57:54 +02:00
|
|
|
:disabled="!isPasswordConfirmed ? true : undefined"
|
2025-05-05 17:23:55 +02:00
|
|
|
@click="updatePassword"
|
2025-05-05 16:57:54 +02:00
|
|
|
>
|
2025-05-05 17:23:55 +02:00
|
|
|
{{ passwordBtn.text }}
|
2025-05-05 16:57:54 +02:00
|
|
|
</button>
|
2025-05-05 16:41:22 +02:00
|
|
|
</li>
|
2025-05-02 17:58:50 +02:00
|
|
|
<li>
|
|
|
|
|
<p>Client : {{ user.client.name }}</p>
|
|
|
|
|
</li>
|
|
|
|
|
<li v-if="user.hasOwnProperty('projects')">
|
|
|
|
|
<p>Nombre de projets : {{ Object.values(user.projects).length }}</p>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
|
|
import { useUserStore } from '../stores/user';
|
2025-05-05 16:57:54 +02:00
|
|
|
import { computed, ref, watch } from 'vue';
|
2025-05-02 17:58:50 +02:00
|
|
|
|
|
|
|
|
const { user } = storeToRefs(useUserStore());
|
2025-05-05 16:41:22 +02:00
|
|
|
|
2025-05-05 17:23:55 +02:00
|
|
|
// Email
|
2025-05-02 17:58:50 +02:00
|
|
|
const email = ref('');
|
2025-05-05 17:23:55 +02:00
|
|
|
const emailBtn = ref({
|
|
|
|
|
text: 'mettre à jour',
|
|
|
|
|
status: 'ready',
|
|
|
|
|
});
|
2025-05-02 17:58:50 +02:00
|
|
|
const isEditingEmail = ref(false);
|
2025-05-05 16:41:22 +02:00
|
|
|
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
2025-05-02 17:58:50 +02:00
|
|
|
|
2025-05-05 17:23:55 +02:00
|
|
|
// Password
|
2025-05-05 16:41:22 +02:00
|
|
|
const password = ref('');
|
2025-05-05 17:23:55 +02:00
|
|
|
const passwordBtn = ref({
|
|
|
|
|
text: 'mettre à jour',
|
|
|
|
|
status: 'ready',
|
|
|
|
|
});
|
2025-05-05 16:57:54 +02:00
|
|
|
const passwordConfirm = ref('');
|
|
|
|
|
const isPasswordConfirmed = computed(() => {
|
|
|
|
|
return (
|
2025-05-05 17:23:55 +02:00
|
|
|
passwordConfirm.value.length > 7 && passwordConfirm.value === password.value
|
2025-05-05 16:57:54 +02:00
|
|
|
);
|
|
|
|
|
});
|
2025-05-05 17:23:55 +02:00
|
|
|
async function updatePassword() {
|
|
|
|
|
passwordBtn.value.text = 'en cours…';
|
|
|
|
|
passwordBtn.value.status = 'pending';
|
|
|
|
|
|
|
|
|
|
const headers = {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
password: password.value,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
const response = await fetch('update-password.json', headers);
|
|
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
|
|
if (json.status === 'success') {
|
|
|
|
|
password.value = '';
|
|
|
|
|
passwordConfirm.value = '';
|
|
|
|
|
passwordBtn.value.text = 'mise à jour réussie';
|
|
|
|
|
passwordBtn.value.status = 'succeed';
|
|
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
passwordBtn.value.text = 'mettre à jour';
|
|
|
|
|
passwordBtn.value.status = 'ready';
|
|
|
|
|
}, 1500);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(json.message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-05-02 17:58:50 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
input.invalid:focus-visible {
|
|
|
|
|
outline: 2px solid #ef8d8d;
|
|
|
|
|
}
|
2025-05-05 17:23:55 +02:00
|
|
|
|
|
|
|
|
.btn--pending {
|
|
|
|
|
background-color: #ffdb88;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.btn--succeed {
|
|
|
|
|
background-color: rgb(182, 211, 255);
|
|
|
|
|
}
|
2025-05-02 17:58:50 +02:00
|
|
|
</style>
|