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

83 lines
2.7 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)">
<div class="field">
<label class="label">{{ $t('auth.forms.name') }}</label>
<div class="control">
<input id="name" type="text" class="input" v-model="form.name" autofocus />
</div>
<field-error :form="form" field="name" />
2020-01-23 23:02:54 +01:00
</div>
2020-01-28 15:33:33 +01:00
<div class="field">
<label class="label">{{ $t('auth.forms.email') }}</label>
<div class="control">
<input id="email" type="email" class="input" v-model="form.email" />
</div>
<field-error :form="form" field="email" />
2020-01-23 23:02:54 +01:00
</div>
2020-01-28 15:33:33 +01:00
<div class="field">
<label class="label">{{ $t('auth.forms.current_password') }}</label>
2020-01-28 15:33:33 +01:00
<div class="control">
<input id="password" type="password" class="input" v-model="form.password" />
</div>
<field-error :form="form" field="password" />
2020-01-23 23:02:54 +01:00
</div>
2020-01-28 15:33:33 +01:00
<div class="field is-grouped">
<div class="control">
<v-button :isLoading="form.isBusy" >{{ $t('commons.update') }}</v-button>
</div>
</div>
</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/user')
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
2020-01-27 21:13:21 +01:00
this.form.patch('/api/user', {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-27 22:04:47 +01:00
localStorage.setItem('user',response.data.username)
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>