2020-01-23 23:02:54 +01:00
|
|
|
<template>
|
2021-10-29 17:12:58 +02:00
|
|
|
<div>
|
|
|
|
<setting-tabs :activeTab="'settings.account'"></setting-tabs>
|
|
|
|
<div class="options-tabs">
|
|
|
|
<form-wrapper>
|
|
|
|
<form @submit.prevent="submitProfile" @keydown="formProfile.onKeydown($event)">
|
|
|
|
<h4 class="title is-4 has-text-grey-light">{{ $t('settings.profile') }}</h4>
|
|
|
|
<form-field :form="formProfile" fieldName="name" :label="$t('auth.forms.name')" autofocus />
|
|
|
|
<form-field :form="formProfile" fieldName="email" inputType="email" :label="$t('auth.forms.email')" />
|
|
|
|
<form-field :form="formProfile" fieldName="password" inputType="password" :label="$t('auth.forms.current_password.label')" :help="$t('auth.forms.current_password.help')" />
|
|
|
|
<form-buttons :isBusy="formProfile.isBusy" :caption="$t('commons.update')" />
|
|
|
|
</form>
|
|
|
|
<form @submit.prevent="submitPassword" @keydown="formPassword.onKeydown($event)">
|
|
|
|
<h4 class="title is-4 pt-6 has-text-grey-light">{{ $t('settings.change_password') }}</h4>
|
|
|
|
<form-field :form="formPassword" fieldName="password" inputType="password" :label="$t('auth.forms.new_password')" />
|
|
|
|
<form-field :form="formPassword" fieldName="password_confirmation" inputType="password" :label="$t('auth.forms.confirm_new_password')" />
|
|
|
|
<form-field :form="formPassword" fieldName="currentPassword" inputType="password" :label="$t('auth.forms.current_password.label')" :help="$t('auth.forms.current_password.help')" />
|
|
|
|
<form-buttons :isBusy="formPassword.isBusy" :caption="$t('auth.forms.change_password')" />
|
|
|
|
</form>
|
|
|
|
</form-wrapper>
|
|
|
|
</div>
|
|
|
|
<vue-footer :showButtons="true">
|
|
|
|
<!-- Cancel button -->
|
|
|
|
<p class="control">
|
|
|
|
<a class="button is-dark is-rounded" @click.stop="exitSettings">
|
|
|
|
{{ $t('commons.close') }}
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
</vue-footer>
|
|
|
|
</div>
|
2020-01-23 23:02:54 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import Form from './../../components/Form'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
data(){
|
|
|
|
return {
|
2021-10-29 17:12:58 +02:00
|
|
|
formProfile: new Form({
|
2020-01-23 23:02:54 +01:00
|
|
|
name : '',
|
|
|
|
email : '',
|
|
|
|
password : '',
|
2021-10-29 17:12:58 +02:00
|
|
|
}),
|
|
|
|
formPassword: new Form({
|
|
|
|
currentPassword : '',
|
|
|
|
password : '',
|
|
|
|
password_confirmation : '',
|
2020-01-23 23:02:54 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-27 21:13:21 +01:00
|
|
|
async mounted() {
|
2021-10-29 17:12:58 +02:00
|
|
|
const { data } = await this.formProfile.get('/api/user')
|
2020-01-27 21:13:21 +01:00
|
|
|
|
2021-10-29 17:12:58 +02:00
|
|
|
this.formProfile.fill(data)
|
2020-01-23 23:02:54 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
methods : {
|
2021-10-29 17:12:58 +02:00
|
|
|
submitProfile(e) {
|
2020-01-23 23:02:54 +01:00
|
|
|
e.preventDefault()
|
|
|
|
|
2021-10-29 17:12:58 +02:00
|
|
|
this.formProfile.put('/api/user', {returnError: true})
|
2020-01-23 23:02:54 +01:00
|
|
|
.then(response => {
|
2021-10-09 19:23:24 +02:00
|
|
|
this.$notify({ type: 'is-success', text: this.$t('auth.forms.profile_saved') })
|
2020-01-23 23:02:54 +01:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if( error.response.status === 400 ) {
|
2020-01-28 15:33:33 +01:00
|
|
|
|
2020-09-25 23:36:11 +02:00
|
|
|
this.$notify({ type: 'is-danger', text: error.response.data.message })
|
2020-01-23 23:02:54 +01:00
|
|
|
}
|
|
|
|
else if( error.response.status !== 422 ) {
|
2021-10-29 17:12:58 +02:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
submitPassword(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
this.formPassword.patch('/api/user/password', {returnError: true})
|
|
|
|
.then(response => {
|
|
|
|
|
|
|
|
this.$notify({ type: 'is-success', text: response.data.message })
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if( error.response.status === 400 ) {
|
|
|
|
|
|
|
|
this.$notify({ type: 'is-danger', text: error.response.data.message })
|
|
|
|
}
|
|
|
|
else if( error.response.status !== 422 ) {
|
|
|
|
|
2020-01-23 23:02:54 +01:00
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|