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>
|
2023-02-17 17:12:53 +01:00
|
|
|
<div v-if="isAdmin" class="notification is-warning">
|
|
|
|
{{ $t('settings.you_are_administrator') }}
|
|
|
|
</div>
|
2021-10-29 17:12:58 +02:00
|
|
|
<form @submit.prevent="submitProfile" @keydown="formProfile.onKeydown($event)">
|
2022-03-24 14:58:30 +01:00
|
|
|
<div v-if="isRemoteUser" class="notification is-warning has-text-centered" v-html="$t('auth.user_account_controlled_by_proxy')" />
|
2021-10-29 17:12:58 +02:00
|
|
|
<h4 class="title is-4 has-text-grey-light">{{ $t('settings.profile') }}</h4>
|
2022-03-24 14:58:30 +01:00
|
|
|
<fieldset :disabled="isRemoteUser">
|
2022-09-18 16:27:42 +02:00
|
|
|
<form-field :form="formProfile" fieldName="name" :label="$t('auth.forms.name')" :maxLength="255" autofocus />
|
|
|
|
<form-field :form="formProfile" fieldName="email" inputType="email" :label="$t('auth.forms.email')" :maxLength="255" />
|
2022-03-24 14:58:30 +01:00
|
|
|
<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')" />
|
|
|
|
</fieldset>
|
2021-10-29 17:12:58 +02:00
|
|
|
</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>
|
2022-03-24 14:58:30 +01:00
|
|
|
<fieldset :disabled="isRemoteUser">
|
2022-09-19 16:53:24 +02:00
|
|
|
<form-password-field :form="formPassword" fieldName="password" :autocomplete="'new-password'" :showRules="true" :label="$t('auth.forms.new_password')" />
|
|
|
|
<form-field :form="formPassword" fieldName="password_confirmation" inputType="password" :autocomplete="'new-password'" :label="$t('auth.forms.confirm_new_password')" />
|
2022-03-24 14:58:30 +01:00
|
|
|
<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')" />
|
|
|
|
</fieldset>
|
2021-10-29 17:12:58 +02:00
|
|
|
</form>
|
2022-06-24 09:11:25 +02:00
|
|
|
<form id="frmDeleteAccount" @submit.prevent="submitDelete" @keydown="formDelete.onKeydown($event)">
|
2022-03-28 13:45:19 +02:00
|
|
|
<h4 class="title is-4 pt-6 has-text-danger">{{ $t('auth.forms.delete_account') }}</h4>
|
|
|
|
<div class="field is-size-7-mobile">
|
|
|
|
{{ $t('auth.forms.delete_your_account_and_reset_all_data')}}
|
|
|
|
</div>
|
|
|
|
<fieldset :disabled="isRemoteUser">
|
|
|
|
<form-field :form="formDelete" fieldName="password" inputType="password" :label="$t('auth.forms.current_password.label')" :help="$t('auth.forms.current_password.help')" />
|
2022-06-24 09:11:25 +02:00
|
|
|
<form-buttons :isBusy="formDelete.isBusy" :caption="$t('auth.forms.delete_your_account')" :submitId="'btnDeleteAccount'" :color="'is-danger'" />
|
2022-03-28 13:45:19 +02:00
|
|
|
</fieldset>
|
|
|
|
</form>
|
2021-10-29 17:12:58 +02:00
|
|
|
</form-wrapper>
|
|
|
|
</div>
|
|
|
|
<vue-footer :showButtons="true">
|
2023-08-21 14:46:05 +02:00
|
|
|
<!-- close button -->
|
2021-10-29 17:12:58 +02:00
|
|
|
<p class="control">
|
2023-08-21 14:46:05 +02:00
|
|
|
<router-link
|
2023-08-30 14:37:59 +02:00
|
|
|
id="btnClose"
|
2023-08-21 14:46:05 +02:00
|
|
|
:to="{ path: $route.params.returnTo, params: { toRefresh: false } }"
|
|
|
|
class="button is-rounded"
|
|
|
|
:class="{'is-dark' : $root.showDarkMode}"
|
|
|
|
tabindex="0"
|
|
|
|
role="button"
|
|
|
|
:aria-label="$t('commons.close_the_x_page', {pagetitle: $router.currentRoute.meta.title})">
|
2021-10-29 17:12:58 +02:00
|
|
|
{{ $t('commons.close') }}
|
2023-08-21 14:46:05 +02:00
|
|
|
</router-link>
|
2021-10-29 17:12:58 +02:00
|
|
|
</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 : '',
|
2022-03-24 14:58:30 +01:00
|
|
|
}),
|
2022-03-28 13:45:19 +02:00
|
|
|
formDelete: new Form({
|
|
|
|
password : '',
|
|
|
|
}),
|
2023-03-12 17:47:40 +01:00
|
|
|
isRemoteUser: this.$root.appConfig.proxyAuth,
|
2023-02-17 17:12:53 +01:00
|
|
|
isAdmin: false,
|
2020-01-23 23:02:54 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-01-27 21:13:21 +01:00
|
|
|
async mounted() {
|
2021-11-07 21:57:22 +01:00
|
|
|
const { data } = await this.formProfile.get('/api/v1/user')
|
2020-01-27 21:13:21 +01:00
|
|
|
|
2023-02-17 17:12:53 +01:00
|
|
|
if( data.is_admin === true ) this.isAdmin = true
|
2022-03-24 14:58:30 +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()
|
|
|
|
|
2022-03-24 15:03:45 +01:00
|
|
|
this.formProfile.put('/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()
|
|
|
|
|
2022-03-24 15:03:45 +01:00
|
|
|
this.formPassword.patch('/user/password', {returnError: true})
|
2021-10-29 17:12:58 +02:00
|
|
|
.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 } });
|
|
|
|
}
|
|
|
|
});
|
2022-03-28 13:45:19 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
submitDelete(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
if(confirm(this.$t('auth.confirm.delete_account'))) {
|
|
|
|
|
|
|
|
this.formDelete.delete('/user', {returnError: true})
|
|
|
|
.then(response => {
|
|
|
|
|
|
|
|
this.$notify({ type: 'is-success', text: this.$t('auth.forms.user_account_successfully_deleted') })
|
|
|
|
this.$router.push({ name: 'register' });
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if( error.response.status === 400 ) {
|
|
|
|
|
|
|
|
this.$notify({ type: 'is-danger', text: error.response.data.message })
|
|
|
|
}
|
|
|
|
else if( error.response.status !== 422 ) {
|
|
|
|
|
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2020-01-23 23:02:54 +01:00
|
|
|
},
|
2023-08-21 14:46:05 +02:00
|
|
|
|
|
|
|
beforeRouteLeave(to, from, next) {
|
|
|
|
if (to.name == 'accounts') {
|
|
|
|
this.$notify({ clean: true })
|
|
|
|
}
|
|
|
|
next()
|
|
|
|
}
|
2020-01-23 23:02:54 +01:00
|
|
|
}
|
|
|
|
</script>
|