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

endret fra user til account

parent 21490b5f
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
Pipeline #221542 failed
describe('Correct navigation links', () => {
<<<<<<< HEAD
it("is sent to error page if page does not exist", () => {
cy.visit('/qwerty')
cy.contains('#msg', '404')
......@@ -23,10 +23,4 @@ describe('Navbar on all pages', () => {
cy.get('nav').should('exist')
})
/*TODO: other pages*/
=======
/*TODO*/
})
describe('Navbar on all pages', () => {
/*TODO*/
>>>>>>> main
})
\ No newline at end of file
......@@ -4,15 +4,15 @@
<p class="infoText">OBS: Kontakt admin dersom du ønsker å oppdatere epost</p><br>
<p>Epost: {{this.user.email}}</p><br>
<p>Epost: {{this.account.email}}</p><br>
<label for="fname">Endre fornavn</label><br>
<input type="text" id="fname" v-model="updatedUser.upFirstname"><br>
<input type="text" id="fname" v-model="updatedAccount.upFirstname"><br>
<label for="password">Endre passord</label><br>
<input type="password" id="password" v-model="updatedUser.upPassword">
<input type="password" id="password" v-model="updatedAccount.upPassword">
<button class="saveBtn" @click="saveAccountSettings">Lagre nytt passord</button>
<button class="saveBtn" @click="saveAccountSettings">Lagre profilendringer</button>
</form>
<br>
......@@ -38,20 +38,17 @@ import router from "../router";
export default {
name: "EditAccount",
computed: {
...mapState(useAuthStore, ['user']),
...mapState(useAuthStore, ['account']),
...mapStores(useAuthStore),
updatedUser() {
updatedAccount() {
return {
upFirstname: this.user.firstname,
upFirstname: this.account.firstname,
upPassword:'',
}
},
iconColor() {
return "#000000"
},
hasProfileImage() {
return this.updatedProfile.upImage.length > 0;
}
},
data() {
return {
......@@ -60,31 +57,31 @@ export default {
},
methods: {
saveAccountSettings(){ //passord
if(this.updatedUser.upPassword.length===0){ //Oppdater ikke passordet dersom man ikke har gjort endringer
const id = this.user.id;
if(this.updatedAccount.upPassword.length===0){ //Oppdater ikke passordet dersom man ikke har gjort endringer
const id = this.account.id;
API.updateAccount(
id,{
firstname:this.updatedUser.upFirstname,
firstname:this.updatedAccount.upFirstname,
password:null,
}
).then((savedUser)=>{
useAuthStore().setUser(savedUser);
).then((savedAccount)=>{
useAuthStore().setAccount(savedAccount);
alert("Bruker oppdatert.")
}).catch((error)=> {
console.log(error)
})
} else {
const id = this.user.id;
const id = this.account.id;
API.updateAccount(
id,{
firstname:this.updatedUser.upFirstname,
password:this.updatedUser.upPassword,
firstname:this.updatedAccount.upFirstname,
password:this.updatedAccount.upPassword,
}
).then((savedUser)=>{
useAuthStore().setUser(savedUser);
alert("Bruker oppdatert.")
).then((savedAccount)=>{
useAuthStore().setAccount(savedAccount);
alert("Konto oppdatert.")
}).catch((error)=> {
console.log(error)
})
......@@ -95,12 +92,11 @@ export default {
alert("Du må bekrefte at du vil slette konto ved å huke av boksen")
}
else {
const id = this.user.id;
const id = this.account.id;
API.deleteAccount(
id
).then((savedUser)=>{
useAuthStore().setUser(savedUser);
alert("Bruker oppdatert.")
).then(()=>{
router.push('/login')
}).catch((error)=> {
alert("Det oppsto en feil ved sletting av bruker")
console.log(error)
......
......@@ -92,17 +92,12 @@ export default {
useAuthStore().setProfile(savedProfile);
alert("profil oppdatert.")
}).catch((error)=> {
console.log(this.updatedProfile.imageUrl)
console.log(error)
})
},
chooseProfilePicture(){
alert("skriv inn bildelenke i feltet, og oppdater innstillinger")
},
deleteUser(){
alert("(Denne knappen gjør ingen ting) bruker slettet")
//API.deleteAccount(this.user.id, token).then
},
changeProfile(){
router.push("/selectProfile");
}
......
......@@ -25,13 +25,8 @@
</RouterLink>
</li>
<li>
<<<<<<< HEAD
<RouterLink :to="'/profileSettings'" :aria-label="'link to settings page'">
<Icon id="settingsIcon" icon="mdi:cog" :color="iconColor" :style="{ fontSize: iconSize }"/>
=======
<RouterLink :to="'/'" :aria-label="'link to settings page'">
<Icon icon="mdi:cog" :color="iconColor" :style="{ fontSize: iconSize }"/>
>>>>>>> main
</RouterLink>
</li>
</ul>
......
......@@ -115,7 +115,6 @@ export const API = {
.catch(err => {console.log(err)})
})
.catch(() => {throw new Error()})
}
},
/**
......@@ -159,7 +158,7 @@ export const API = {
headers: { Authorization: `Bearer ${authStore.token}` },
})
.then((response) => {
authStore.setUser(response.data)
authStore.setAccount(response.data)
return response.data;
}).catch(() => {
throw new Error("Error when updating account: ");
......
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