|
@ -1,6 +1,6 @@ |
|
|
<template> |
|
|
<template> |
|
|
<h1 class="title is-2">Profile</h1> |
|
|
<h1 class="title is-2">Profile</h1> |
|
|
<form @submit.prevent="update"> |
|
|
<form @submit="update"> |
|
|
<div class="tile is-ancestor"> |
|
|
<div class="tile is-ancestor"> |
|
|
<div class="tile is-4 is-vertical is-parent"> |
|
|
<div class="tile is-4 is-vertical is-parent"> |
|
|
<div class="tile is-child box"> |
|
|
<div class="tile is-child box"> |
|
@ -8,7 +8,7 @@ |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
|
<label class="label">Username</label> |
|
|
<label class="label">Username</label> |
|
|
<div class="control"> |
|
|
<div class="control"> |
|
|
<input class="input" type="text" :value="user.username"> |
|
|
<input class="input" type="text" v-model="user.username"> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
@ -21,7 +21,7 @@ |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
|
<label class="label">Email</label> |
|
|
<label class="label">Email</label> |
|
|
<div class="control"> |
|
|
<div class="control"> |
|
|
<input class="input" type="email" :value="user.email"> |
|
|
<input class="input" type="email" v-model="user.email"> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
@ -31,7 +31,7 @@ |
|
|
<p class="title">Change Password</p> |
|
|
<p class="title">Change Password</p> |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
|
<p class="control has-icons-left"> |
|
|
<p class="control has-icons-left"> |
|
|
<input class="input" type="password" placeholder="Current Password" v-model="currentPassword"> |
|
|
<input class="input" type="password" placeholder="Current Password" v-model="user.currentPassword"> |
|
|
<span class="icon is-small is-left"> |
|
|
<span class="icon is-small is-left"> |
|
|
<i class="fas fa-lock"></i> |
|
|
<i class="fas fa-lock"></i> |
|
|
</span> |
|
|
</span> |
|
@ -39,7 +39,7 @@ |
|
|
</div> |
|
|
</div> |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
|
<p class="control has-icons-left"> |
|
|
<p class="control has-icons-left"> |
|
|
<input class="input" type="password" placeholder="New Password" v-model="newPassword"> |
|
|
<input class="input" type="password" placeholder="New Password" v-model="user.newPassword"> |
|
|
<span class="icon is-small is-left"> |
|
|
<span class="icon is-small is-left"> |
|
|
<i class="fas fa-lock"></i> |
|
|
<i class="fas fa-lock"></i> |
|
|
</span> |
|
|
</span> |
|
@ -47,7 +47,7 @@ |
|
|
</div> |
|
|
</div> |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
|
<p class="control has-icons-left"> |
|
|
<p class="control has-icons-left"> |
|
|
<input class="input" type="password" placeholder="Confirm Password" v-model="repeatNewPassword"> |
|
|
<input class="input" type="password" placeholder="Confirm Password" v-model="user.repeatNewPassword"> |
|
|
<span class="icon is-small is-left"> |
|
|
<span class="icon is-small is-left"> |
|
|
<i class="fas fa-lock"></i> |
|
|
<i class="fas fa-lock"></i> |
|
|
</span> |
|
|
</span> |
|
@ -55,13 +55,16 @@ |
|
|
</div> |
|
|
</div> |
|
|
<div class="field"> |
|
|
<div class="field"> |
|
|
<p class="control"> |
|
|
<p class="control"> |
|
|
<button class="button is-primary" type="submit"> |
|
|
<button class="button is-primary is-rounded" type="submit"> |
|
|
Update |
|
|
Update |
|
|
</button> |
|
|
</button> |
|
|
</p> |
|
|
</p> |
|
|
</div> |
|
|
</div> |
|
|
<div class="notification is-danger has-text-centered mt-5" v-if="msg"> |
|
|
<div class="notification is-danger has-text-centered mt-5" v-if="msgError"> |
|
|
<b>{{ msg }}</b> |
|
|
<b>{{ msgError }}</b> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div class="notification is-success has-text-centered mt-5" v-else-if="msgSuccess"> |
|
|
|
|
|
<b>{{ msgSuccess }}</b> |
|
|
</div> |
|
|
</div> |
|
|
<div class="notification is-primary is-light mt-5" v-else> |
|
|
<div class="notification is-primary is-light mt-5" v-else> |
|
|
<p>According to the traditional advice—which is still good—a strong password:</p> |
|
|
<p>According to the traditional advice—which is still good—a strong password:</p> |
|
@ -82,38 +85,57 @@ |
|
|
import {Vue} from "vue-class-component"; |
|
|
import {Vue} from "vue-class-component"; |
|
|
|
|
|
|
|
|
interface User { |
|
|
interface User { |
|
|
|
|
|
_id: string, |
|
|
username: string, |
|
|
username: string, |
|
|
registered: string |
|
|
email: string, |
|
|
|
|
|
registered: string, |
|
|
|
|
|
currentPassword: string, |
|
|
|
|
|
newPassword: string, |
|
|
|
|
|
repeatNewPassword: string, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export default class Profile extends Vue { |
|
|
export default class Profile extends Vue { |
|
|
private msg = ''; |
|
|
private msgSuccess = ''; |
|
|
|
|
|
private msgError = ''; |
|
|
private user!: User; |
|
|
private user!: User; |
|
|
private date!: string; |
|
|
private date!: string; |
|
|
|
|
|
|
|
|
private username = '' |
|
|
|
|
|
private email = '' |
|
|
|
|
|
private currentPassword = '' |
|
|
|
|
|
private newPassword = '' |
|
|
|
|
|
private repeatNewPassword = '' |
|
|
|
|
|
|
|
|
|
|
|
created() { |
|
|
created() { |
|
|
this.user = this.$store.getters.user |
|
|
this.user = this.$store.getters.user |
|
|
this.date = new Date(this.user.registered).toLocaleString() |
|
|
this.date = new Date(this.user.registered).toLocaleString() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private update() { |
|
|
private update() { |
|
|
|
|
|
if (this.user.newPassword != this.user.repeatNewPassword) { |
|
|
|
|
|
this.msgError = 'Passwords do not match!' |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let user = { |
|
|
let user = { |
|
|
username: this.username, |
|
|
_id: this.user._id, |
|
|
email: this.email, |
|
|
username: this.user.username, |
|
|
password: this.currentPassword, |
|
|
email: this.user.email, |
|
|
newPassword: this.newPassword, |
|
|
password: this.user.currentPassword, |
|
|
repeatNewPassword: this.repeatNewPassword |
|
|
newPassword: this.user.newPassword, |
|
|
|
|
|
repeatNewPassword: this.user.repeatNewPassword |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.$store.dispatch('updateUser', user) |
|
|
this.$store.dispatch('updateUser', user) |
|
|
.then(() => this.$router.push({name: 'Profile', params: {username: this.username}})) |
|
|
.then(() => { |
|
|
.catch((err: any) => this.msg = err.response.data.errors.message || err.message || 'Something went wrong!') |
|
|
this.msgSuccess = 'User updated!'; |
|
|
|
|
|
this.$router.push({ |
|
|
|
|
|
name: 'Profile', |
|
|
|
|
|
params: {username: this.user.username} |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
.catch((err: any) => { |
|
|
|
|
|
this.msgError = err.data.errors.message || err.message || 'Something went wrong!'; |
|
|
|
|
|
this.$router.push({ |
|
|
|
|
|
name: 'Profile', |
|
|
|
|
|
params: {username: this.user.username} |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|