From b0b98cee7ecadc76161d08c0b07926f9c726dfd7 Mon Sep 17 00:00:00 2001
From: ingrid <ingrimeg@stud.ntnu.no>
Date: Mon, 24 Apr 2023 12:03:29 +0200
Subject: [PATCH] v-modeling

---
 package-lock.json             |  4 ++--
 package.json                  |  1 +
 src/components/Navbar.vue     |  3 +--
 src/util/API.js               | 15 ++++++++++++++-
 src/views/ProfileSettings.vue | 20 +++++++++++++++++---
 5 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index d4c3290..7ab1df6 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,6 +9,7 @@
       "version": "0.0.0",
       "dependencies": {
         "@iconify/iconify": "^3.1.0",
+        "async": "^3.2.4",
         "pinia": "^2.0.28",
         "sass": "^1.62.0",
         "vue": "^3.2.45",
@@ -1394,8 +1395,7 @@
     "node_modules/async": {
       "version": "3.2.4",
       "resolved": "https://registry.npmjs.org/async/-/async-3.2.4.tgz",
-      "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ==",
-      "dev": true
+      "integrity": "sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ=="
     },
     "node_modules/async-foreach": {
       "version": "0.1.3",
diff --git a/package.json b/package.json
index a08af32..904a1b5 100644
--- a/package.json
+++ b/package.json
@@ -12,6 +12,7 @@
   },
   "dependencies": {
     "@iconify/iconify": "^3.1.0",
+    "async": "^3.2.4",
     "pinia": "^2.0.28",
     "sass": "^1.62.0",
     "vue": "^3.2.45",
diff --git a/src/components/Navbar.vue b/src/components/Navbar.vue
index b71d45b..08a12f6 100644
--- a/src/components/Navbar.vue
+++ b/src/components/Navbar.vue
@@ -56,11 +56,9 @@ export default {
 </script>
 
 <style scoped lang="scss">
-
 #logoContainer {
     background-color: white;
     border-radius: 50%;
-
 }
 #logoContainer img{
     width:70%;
@@ -74,6 +72,7 @@ nav {
     background-color: base.$green;
     margin:0;
     padding:0;
+    z-index: 999;
 }
 
 ul {
diff --git a/src/util/API.js b/src/util/API.js
index fadc566..4025a5c 100644
--- a/src/util/API.js
+++ b/src/util/API.js
@@ -30,7 +30,7 @@ export const API = {
     /**
      * Updates profile
      */
-    updateAccount: async () => {
+    updateAccount: async (id, password) => {
         return axios.put(`${import.meta.env.VITE_BACKEND_URL}/account/{id}`)
             .then((response) => {
                 return response.data;
@@ -58,6 +58,19 @@ export const API = {
 
     },
 
+    updateProfile: async (id, token) => {
+        return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/profile/{id}`, {
+            headers: { Authorization: `Bearer ${token}` },
+        })
+            .then((response) => {
+                return response.data;
+            })
+            .catch(() => {
+                throw new Error("Account not found or not accessible");
+            });
+
+    },
+
 
 
 
diff --git a/src/views/ProfileSettings.vue b/src/views/ProfileSettings.vue
index 67d3629..13e8d11 100644
--- a/src/views/ProfileSettings.vue
+++ b/src/views/ProfileSettings.vue
@@ -76,10 +76,11 @@
 
             <p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p>
 
-            <h2>Epost: {{user.username}}</h2>
+            <p>Epost:</p>
+            <p>{{user.username}}</p><br>
 
-            <label for="password">Passord</label><br>
-            <input type="password" id="password">
+            <label for="password">Endre passord</label><br>
+            <input type="password" id="password" v-model="user.password">
 
             <button class="saveBtn" @click="saveAccountSettings">Lagre kontoinnstillinger</button>
 
@@ -103,6 +104,7 @@
 <script>
 
 import {Icon} from "@iconify/vue";
+import {API} from "@/util/API";
 
 export default {
     name: "ProfileSettings",
@@ -136,9 +138,20 @@ export default {
     methods: {
       saveUserSettings(){
         alert("(Denne knappen gjør ingen ting) brukerinnstillinger lagret!")
+          API.updateProfile(
+              this.user.id,
+              this.profile.name,
+              this.profile.isRestricted,
+              this.profile.image,
+          );
+
       },
       saveAccountSettings(){
         alert("(Denne knappen gjør ingen ting) konto oppdatert")
+          /*API.updateAccount(
+              this.user.id,
+              this.user.password,
+              token);*/
       },
       deleteAccount(){
           if(this.deletionConfirmation===false){
@@ -146,6 +159,7 @@ export default {
           }
           else {
               alert("(Denne knappen gjør ingen ting) men  account deleted")
+              //API.deleteAccount(this.user.id, token);
           }
 
       },
-- 
GitLab