diff --git a/dashboard/components/settings/Account.vue b/dashboard/components/settings/Account.vue index 0fd411c..05c1bef 100644 --- a/dashboard/components/settings/Account.vue +++ b/dashboard/components/settings/Account.vue @@ -2,12 +2,18 @@ import type { SettingsTemplateEntry } from './Template.vue'; const entries: SettingsTemplateEntry[] = [ + { id: 'change_pass', title: 'Change password', text: 'Change your password' }, { id: 'delete', title: 'Delete account', text: 'Delete your account' }, ] +const { user } = useLoggedUser(); const { setToken } = useAccessToken(); +const canChangePassword = useFetch('/api/user/password/can_change', { + headers: useComputedHeaders({ useSnapshotDates: false }) +}); + async function deleteAccount() { const sure = confirm("Are you sure you want to delete this account ?"); if (!sure) return; @@ -20,11 +26,57 @@ async function deleteAccount() { location.href = "/login" } +const old_password = ref(""); +const new_password = ref(""); + +const { createAlert } = useAlert() + +async function changePassword() { + + + try { + const res = await $fetch("/api/user/password/change", { + ...signHeaders({ 'Content-Type': 'application/json' }), + method: "POST", + body: JSON.stringify({ old_password: old_password.value, new_password: new_password.value }) + }) + + if (!res) throw Error('No response'); + + if (res.error) return createAlert('Error', res.message, 'far fa-triangle-exclamation', 5000); + + + old_password.value = ''; + new_password.value = ''; + + return createAlert('Success', 'Password changed successfully', 'far fa-circle-check', 5000); + + } catch (ex) { + console.error(ex); + createAlert('Error', 'Internal error', 'far fa-triangle-exclamation', 5000); + } + +} + + +