2FAuth/resources/js/views/auth/password/Reset.vue

97 lines
3.9 KiB
Vue
Raw Normal View History

2020-01-14 23:50:07 +01:00
<template>
<div class="section">
<div class="columns is-mobile is-centered">
<div class="column is-two-thirds-tablet is-half-desktop is-one-third-widescreen is-one-quarter-fullhd">
<h1 class="title">{{ $t('auth.forms.new_password') }}</h1>
<form method="POST">
2020-01-14 23:50:07 +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="email" disabled readonly />
2020-01-14 23:50:07 +01:00
</div>
<p class="help is-danger" v-if="validationErrors.email">{{ validationErrors.email.toString() }}</p>
</div>
<div class="field">
<label class="label">{{ $t('auth.forms.new_password') }}</label>
2020-01-14 23:50:07 +01:00
<div class="control">
<input id="password" type="password" class="input" v-model="password" required />
</div>
<p class="help is-danger" v-if="validationErrors.password">{{ validationErrors.password.toString() }}</p>
</div>
<div class="field">
<label class="label">{{ $t('auth.forms.confirm_password') }}</label>
2020-01-14 23:50:07 +01:00
<div class="control">
<input id="password_confirmation" type="password" class="input" v-model="password_confirmation" required />
</div>
<p class="help is-danger" v-if="validationErrors.password_confirmation">{{ validationErrors.password_confirmation.toString() }}</p>
</div>
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-link" @click="handleSubmit">{{ $t('auth.forms.change_password') }}</button>
2020-01-14 23:50:07 +01:00
</div>
<div class="control">
<router-link :to="{ name: 'login' }" class="button is-text">{{ $t('commons.cancel') }}</router-link>
</div>
</div>
</form>
<br />
<span class="tag is-danger" v-if="errorMessage">
{{ errorMessage }}
</span>
2020-01-14 23:50:07 +01:00
</div>
</div>
</div>
</template>
<script>
export default {
data(){
return {
email : '',
password : '',
password_confirmation : '',
token : '',
validationErrors: {},
errorMessage: ''
2020-01-14 23:50:07 +01:00
}
},
created () {
this.email = this.$route.query.email
this.token = this.$route.params.token
},
methods : {
2020-01-19 22:29:36 +01:00
handleSubmit(e) {
2020-01-14 23:50:07 +01:00
e.preventDefault()
this.validationErrors = {}
2020-01-19 22:29:36 +01:00
axios.post('/api/password/reset', {
email: this.email,
password: this.password,
password_confirmation : this.password_confirmation,
token: this.token
})
.then(response => {
2020-01-16 22:21:05 +01:00
this.$router.go('/');
2020-01-19 22:29:36 +01:00
})
.catch(error => {
2020-01-14 23:50:07 +01:00
if( error.response.data.errors ) {
this.validationErrors = error.response.data.errors
}
else if( error.response.data.resetFailed ) {
this.errorMessage = error.response.data.resetFailed
}
2020-01-14 23:50:07 +01:00
else {
2020-01-17 00:23:38 +01:00
this.$router.push({ name: 'genericError', params: { err: error.response } });
2020-01-14 23:50:07 +01:00
}
2020-01-19 22:29:36 +01:00
});
2020-01-14 23:50:07 +01:00
}
},
}
</script>