2FAuth/resources/js/views/profile/Account.vue

59 lines
1.9 KiB
Vue
Raw Normal View History

2020-01-23 23:02:54 +01:00
<template>
2020-02-13 08:50:20 +01:00
<form-wrapper :fail="fail" :success="success">
2020-01-28 15:33:33 +01:00
<form @submit.prevent="handleSubmit" @keydown="form.onKeydown($event)">
<form-field :form="form" fieldName="name" :label="$t('auth.forms.name')" autofocus />
<form-field :form="form" fieldName="email" inputType="email" :label="$t('auth.forms.email')" />
<form-field :form="form" fieldName="password" inputType="password" :label="$t('auth.forms.current_password.label')" :help="$t('auth.forms.current_password.help')" :hasOffset="true" />
<form-buttons :isBusy="form.isBusy" :caption="$t('commons.update')" />
2020-01-28 15:33:33 +01:00
</form>
</form-wrapper>
2020-01-23 23:02:54 +01:00
</template>
<script>
import Form from './../../components/Form'
export default {
data(){
return {
2020-01-28 15:33:33 +01:00
success: '',
fail: '',
2020-01-23 23:02:54 +01:00
form: new Form({
name : '',
email : '',
password : '',
})
}
},
2020-01-27 21:13:21 +01:00
async mounted() {
const { data } = await this.form.get('/api/profile/account')
2020-01-27 21:13:21 +01:00
this.form.fill(data)
2020-01-23 23:02:54 +01:00
},
methods : {
handleSubmit(e) {
e.preventDefault()
2020-01-28 15:33:33 +01:00
this.fail = ''
this.success = ''
2020-01-23 23:02:54 +01:00
this.form.patch('/api/profile/account', {returnError: true})
2020-01-23 23:02:54 +01:00
.then(response => {
2020-01-28 15:33:33 +01:00
this.success = response.data.message
2020-01-23 23:02:54 +01:00
})
.catch(error => {
if( error.response.status === 400 ) {
2020-01-28 15:33:33 +01:00
this.fail = error.response.data.message
2020-01-23 23:02:54 +01:00
}
else if( error.response.status !== 422 ) {
this.$router.push({ name: 'genericError', params: { err: error.response } });
}
});
}
},
}
</script>