Skip to content
Snippets Groups Projects
Commit 52ae287e authored by Ingrid Martinsheimen Egge's avatar Ingrid Martinsheimen Egge :cow2:
Browse files

man kan oppdatere fornavn og passord

parent 7b4d0274
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
<p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p><br> <p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p><br>
<p>Epost: {{user.email}}</p><br> <p>Epost: {{this.user.email}}</p><br>
<label for="fname">Endre fornavn</label><br>
<input type="text" id="fname" v-model="updatedUser.upFirstname"><br>
<label for="password">Endre passord</label><br> <label for="password">Endre passord</label><br>
<input type="password" id="password" v-model="this.currentUser.newPassword"> <input type="password" id="password" v-model="updatedUser.upPassword">
<button class="saveBtn" @click="saveAccountSettings">Lagre nytt passord</button> <button class="saveBtn" @click="saveAccountSettings">Lagre nytt passord</button>
...@@ -27,15 +30,138 @@ ...@@ -27,15 +30,138 @@
</template> </template>
<script> <script>
import {mapStores} from "pinia"; import {mapState, mapStores} from "pinia";
import {Icon} from "@iconify/vue"; import {Icon} from "@iconify/vue";
import {API} from "@/util/API"; import {API} from "@/util/API";
import { useAuthStore } from "@/stores/authStore"; import { useAuthStore } from "@/stores/authStore";
import router from "../router";
export default { export default {
name: "EditAccount" name: "EditAccount",
computed: {
...mapState(useAuthStore, ['user']),
...mapStores(useAuthStore),
updatedUser() {
return {
upFirstname: this.user.firstname,
upPassword:'',
}
},
iconColor() {
return "#000000"
},
hasProfileImage() {
return this.updatedProfile.upImage.length > 0;
}
},
data() {
return {
deletionConfirmation: false,
}
},
methods: {
saveAccountSettings(){ //passord
if(this.updatedUser.upPassword.length===0){ //Oppdater ikke passordet dersom man ikke har gjort endringer
const id = this.user.id;
API.updateAccount(
id,{
firstname:this.updatedUser.upFirstname,
password:null,
}
).then((savedUser)=>{
useAuthStore().setUser(savedUser);
alert("Bruker oppdatert.")
}).catch((error)=> {
console.log(error)
})
} else {
const id = this.user.id;
API.updateAccount(
id,{
firstname:this.updatedUser.upFirstname,
password:this.updatedUser.upPassword,
}
).then((savedUser)=>{
useAuthStore().setUser(savedUser);
alert("Bruker oppdatert.")
}).catch((error)=> {
console.log(error)
})
}
},
deleteAccount(){
if(this.deletionConfirmation===false){
alert("Du må bekrefte at du vil slette konto ved å huke av boksen")
}
else {
alert("(Denne knappen gjør ingen ting) men account deleted")
API.deleteAccount(this.user.id, token);
}
},
}
} }
</script> </script>
<style scoped> <style scoped lang="scss">
main {
background-color: white;
color:black;
display:flex;
justify-content: center;
align-items: center;
flex-direction: column;
width: 100%;
text-align: left;
left:0;
}
.infoText {
background-color: white;
padding: .5em;
margin: .4em;
}
form {
background-color: base.$grey;
color: black;
align-content: end;
padding: 2em;
margin-top: 2em;
margin-bottom: 2em;
}
input[type="text"],
input[type="password"]{
width: 100%;
padding: .5em;
}
button {
background-color: base.$red;
color: black;
border: 1px solid black;
margin: 1em;
}
button:hover{
background-color: #282828;
}
.saveBtn, .delBtn {
background-color: base.$green;
color: white;
font-weight: bold;
padding:.9em;
border:none;
}
.delBtn {
background-color: darkred;
}
#dangerZone {
color: darkred;
}
</style> </style>
\ No newline at end of file
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<label for="restricted"> Begrenset - Kan ikke redigere ukeplan eller handleliste</label><br> <label for="restricted"> Begrenset - Kan ikke redigere ukeplan eller handleliste</label><br>
<br> <br>
<h3>Profilbilde</h3> <h3>Profilbilde</h3><br>
<div id="changeUserImage"> <div id="changeUserImage">
<div v-if="hasProfileImage" id = "profilepicture-container"> <div v-if="hasProfileImage" id = "profilepicture-container">
<img width="50" :src="this.updatedProfile.upImage" alt="profile picture"> <img width="50" :src="this.updatedProfile.upImage" alt="profile picture">
...@@ -31,11 +31,14 @@ ...@@ -31,11 +31,14 @@
<div v-else id = "profilepicture-container"> <div v-else id = "profilepicture-container">
<Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '30px'}" /> <Icon icon="material-symbols:person" :color=iconColor :style="{ fontSize: '30px'}" />
</div> </div>
<button @click="chooseProfilePicture">Endre bilde</button>
</div>
<label for="chooseImageUrl">Bilde-URL:</label>
<input type="text" id="chooseImageUrl" v-model="this.updatedProfile.upImage">
</div>
<br><br>
<div id = "submitbuttonBox"> <div id = "submitbuttonBox">
<button @click=" saveUserSettings">Submit</button> <button class="saveBtn" @click=" saveUserSettings">Lagre profilendringer</button>
<button class="delBtn" @click="deleteUser">Slett brukerprofil</button> <button class="delBtn" @click="deleteUser">Slett brukerprofil</button>
</div> </div>
...@@ -86,32 +89,15 @@ export default { ...@@ -86,32 +89,15 @@ export default {
restricted:this.updatedProfile.upRestricted, restricted:this.updatedProfile.upRestricted,
} }
).then((savedProfile)=>{ ).then((savedProfile)=>{
console.log(this.updatedProfile.upName)
useAuthStore().setProfile(savedProfile); useAuthStore().setProfile(savedProfile);
alert("profil oppdatert.") alert("profil oppdatert.")
}).catch((error)=> { }).catch((error)=> {
console.log(this.updatedProfile.imageUrl)
console.log(error) console.log(error)
}) })
}, },
chooseProfilePicture(){ chooseProfilePicture(){
alert("velgBilde") alert("skriv inn bildelenke i feltet, og oppdater innstillinger")
},
saveAccountSettings(){ //passord
if(this.currentUser.newPassword.length===0){
alert("Det er ikke gjort endringer, og passordet vil ikke bli oppdatert")
} else {
alert("(Denne knappen gjør ingen ting) konto oppdatert")
}
},
deleteAccount(){
if(this.deletionConfirmation===false){
alert("Du må bekrefte at du vil slette konto ved å huke av boksen")
}
else {
alert("(Denne knappen gjør ingen ting) men account deleted")
//API.deleteAccount(this.user.id, token);
}
}, },
deleteUser(){ deleteUser(){
alert("(Denne knappen gjør ingen ting) bruker slettet") alert("(Denne knappen gjør ingen ting) bruker slettet")
......
...@@ -124,17 +124,34 @@ export const API = { ...@@ -124,17 +124,34 @@ export const API = {
}, },
/** /**
* Updates profile *
* @param id account id
* @param request password and firstname
* @returns {Promise<*>}
*/ */
updateAccount: async (id, password) => { updateAccount: async (id, request) => {
return axios.put(`${import.meta.env.VITE_BACKEND_URL}/account/{id}`) const authStore = useAuthStore();
if (!authStore.isLoggedIn) {
throw new Error();
}
return axios.put(`${import.meta.env.VITE_BACKEND_URL}/account/${id}`,request, {
headers: { Authorization: `Bearer ${authStore.token}` },
})
.then((response) => { .then((response) => {
authStore.setUser(response.data)
return response.data; return response.data;
}).catch(() => { }).catch(() => {
throw new Error(); throw new Error("Error when updating account: ");
}); });
}, },
/**
* Updates the profile name, restriction and profile image
* @param id profile id
* @param request
* @returns {Promise<*>}
*/
updateProfile: async (id, request) => { updateProfile: async (id, request) => {
const authStore = useAuthStore(); const authStore = useAuthStore();
if (!authStore.isLoggedIn) { if (!authStore.isLoggedIn) {
......
<template> <template>
<main> <main>
<EditProfile></EditProfile> <EditProfile></EditProfile>
<EditAccount></EditAccount>
<!--<EditAccount></EditAccount>-->
</main> </main>
</template> </template>
<script setup> <script setup>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment