diff --git a/public/site/config/config.php b/public/site/config/config.php index 7e92b30..c6cb731 100644 --- a/public/site/config/config.php +++ b/public/site/config/config.php @@ -33,6 +33,7 @@ return [ require(__DIR__ . '/routes/save-page.php'), require(__DIR__ . '/routes/save-file.php'), require(__DIR__ . '/routes/remove-file.php'), + require(__DIR__ . '/routes/update-password.php'), require(__DIR__ . '/routes/upload-pdf.php'), require(__DIR__ . '/routes/validate-brief.php'), require(__DIR__ . '/routes/request-project-creation.php'), diff --git a/public/site/config/routes/update-password.php b/public/site/config/routes/update-password.php new file mode 100644 index 0000000..001b0dc --- /dev/null +++ b/public/site/config/routes/update-password.php @@ -0,0 +1,22 @@ + '/update-password.json', + 'method' => 'POST', + 'action' => function() { + $json = file_get_contents("php://input"); + $data = json_decode($json); + + try { + kirby()->user()->changePassword($data->password); + return [ + 'status' => 'success' + ]; + } catch (\Throwable $th) { + return [ + 'status' => 'error', + 'message' => 'Impossible de mettre à jour le mot de passe : ' . $th->getMessage() . ' in file ' . $th->getFile() . ' line ' . $th->getLine() + ]; + } + } +]; \ No newline at end of file diff --git a/src/views/Account.vue b/src/views/Account.vue index 86a3ade..0bf10d4 100644 --- a/src/views/Account.vue +++ b/src/views/Account.vue @@ -17,7 +17,13 @@ required />

Email : {{ user.email }}

- + @@ -43,9 +49,11 @@ />
  • @@ -63,21 +71,66 @@ import { computed, ref, watch } from 'vue'; const { user } = storeToRefs(useUserStore()); +// Email const email = ref(''); +const emailBtn = ref({ + text: 'mettre à jour', + status: 'ready', +}); const isEditingEmail = ref(false); const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; +// Password const password = ref(''); +const passwordBtn = ref({ + text: 'mettre à jour', + status: 'ready', +}); const passwordConfirm = ref(''); const isPasswordConfirmed = computed(() => { return ( - passwordConfirm.value.length > 0 && passwordConfirm.value === password.value + passwordConfirm.value.length > 7 && passwordConfirm.value === password.value ); }); +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); + } +}