2FAuth/resources/js/views/auth/RequestReset.vue

52 lines
1.8 KiB
Vue
Raw Normal View History

2023-10-30 15:13:50 +01:00
<script setup>
import Form from '@/components/formElements/Form'
import { useNotifyStore } from '@/stores/notify'
const notify = useNotifyStore()
const route = useRoute()
const isWebauthnReset = route.name == 'webauthn.lost'
2023-10-30 15:13:50 +01:00
const form = reactive(new Form({
email: '',
}))
/**
* Submits the reset request to the backend
2023-10-30 15:13:50 +01:00
*/
function requestPasswordReset(e) {
notify.clear()
form.post(isWebauthnReset ? '/webauthn/lost' : '/user/password/lost', {returnError: true})
2023-10-30 15:13:50 +01:00
.then(response => {
notify.success({ text: response.data.message, duration:-1 })
})
.catch(error => {
if( error.response.data.requestFailed ) {
notify.alert({ text: error.response.data.requestFailed, duration:-1 })
}
else if( error.response.status !== 422 ) {
notify.error(error)
}
})
}
onBeforeRouteLeave(() => {
notify.clear()
})
</script>
<template>
<FormWrapper :title="$t(isWebauthnReset ? 'auth.webauthn.account_recovery' : 'auth.forms.reset_password')" :punchline="$t(isWebauthnReset ? 'auth.webauthn.recovery_punchline' : 'auth.forms.reset_punchline')">
2023-10-30 15:13:50 +01:00
<form @submit.prevent="requestPasswordReset" @keydown="form.onKeydown($event)">
<FormField v-model="form.email" fieldName="email" :fieldError="form.errors.get('email')" label="auth.forms.email" autofocus />
<FormButtons
:submitId="'btnSendResetPwd'"
:isBusy="form.isBusy"
:caption="$t(isWebauthnReset ? 'auth.webauthn.send_recovery_link' : 'auth.forms.send_password_reset_link')"
2023-10-30 15:13:50 +01:00
:showCancelButton="true"
cancelLandingView="login" />
</form>
<VueFooter />
</FormWrapper>
</template>