Skip to content
Snippets Groups Projects
Commit 2860afcd authored by Mathias Myhrvold Olsen's avatar Mathias Myhrvold Olsen
Browse files

Settings according to Task 5

parent 794a6583
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,10 @@ document.getElementById("cancelButton").addEventListener("click", function(){
*/
function editUser (event) {
event.preventDefault();
let newInformation = {};
let newInformation = {
"username": document.getElementById('username').value,
"password": document.getElementById('password').value
};
fetch('../api/user/'+sessionStorage.getItem("userId"), {
method: "PUT",
......@@ -20,9 +23,20 @@ function editUser (event) {
if (response === true) {
alert("Bruker oppdatert");
window.location.href = "../app.html";
loadApplication(newInformation);
} else {
alert("Brukernavn eksisterer fra før, vennligst skriv inn et nytt brukernavn");
}
})
.catch(error => console.error(error));
}
/**
* Adds user information to sessionStorage and redirects to app.html
* @param user contains user information as a JSON object
*/
function loadApplication(user){
sessionStorage.setItem("userId", user.userId);
sessionStorage.setItem("username", user.username);
window.location.href = "../app.html"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment