diff --git a/public/profile.html b/public/profile.html new file mode 100644 index 0000000..2cc70c7 --- /dev/null +++ b/public/profile.html @@ -0,0 +1,86 @@ + + + + + + + Settings + + + + + + + + + + +
+

Settings

+ +
+

Profile

+ +
+ +
+ + +
+
+ +
+ + +
+
+ +
+

Credentials

+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+ + +
+
+ + +
+ + \ No newline at end of file diff --git a/public/profile.js b/public/profile.js new file mode 100644 index 0000000..9db589c --- /dev/null +++ b/public/profile.js @@ -0,0 +1,38 @@ +import {EditAccount, EditPassword, edit, edit_password} from "/scripts/api/account.js"; + +document.querySelector("#form-account").addEventListener("submit", async (e) => { + e.preventDefault(); + + const username = document.querySelector("#username").value; + + const account_update = new EditAccount(username); + const res = await edit(account_update); + if (res.ok) { + window.location = "/home.html"; + } else { + console.error(res.value); + alert(`Action not successful: ${res.value}`); + } +}); + +document.querySelector("#form-credential").addEventListener("submit", async (e) => { + e.preventDefault(); + + const current_password = document.querySelector("#current-password").value; + const new_password1 = document.querySelector("#new-password1").value; + const new_password2 = document.querySelector("#new-password2").value; + + if (new_password1 !== new_password2) { + alert("Passwords didn't match. Enter them again and retry."); + return; + } + + const password_update = new EditPassword(current_password, new_password1); + const res = await edit_password(password_update); + if (res.ok) { + window.location = "/home.html"; + } else { + console.error(res.value); + alert(`Action not successful: ${res.value}`); + } +}); diff --git a/public/scripts/api/account.js b/public/scripts/api/account.js index d93a202..cf1eecd 100644 --- a/public/scripts/api/account.js +++ b/public/scripts/api/account.js @@ -102,15 +102,15 @@ export async function edit(account) { /// :param current_password the accounts current password /// :param new_password the new password for the account /// :return `Account` updated account -export async function edit_password(current_password, new_password) { - const request = new Request(`${BASE_ACCOUNT_URL}`, { +export async function edit_password(edit_password) { + const request = new Request(`${BASE_ACCOUNT_URL}/password`, { method: "PUT", headers: new Headers({ "Content-Type": "application/json", }), body: JSON.stringify({ - current_password: current_password, - new_password: new_password + current_password: edit_password.current_password, + new_password: edit_password.new_password }), credentials: 'include', });