import Vue from 'vue'; import {isObject} from 'lodash'; export default Vue.component('login-form', { props: { user: { type: Object, required: false, default: function () { return { email: '', password: '', }; }, } }, data: function () { return { showSpinner: false, } }, mounted: function () { (this.$refs.email as HTMLElement).focus(); }, methods: { // Handle a login request eminating from the form. If 2FA is required the // user will be presented with the 2FA modal window. submitForm: function () { this.$data.showSpinner = true; this.$flash.clear(); this.$store.dispatch('auth/login', {user: this.$props.user.email, password: this.$props.user.password}) .then(response => { if (response.complete) { return window.location = response.intended; } this.$props.user.password = ''; this.$data.showSpinner = false; this.$router.push({name: 'checkpoint', query: {token: response.token}}); }) .catch(err => { this.$props.user.password = ''; this.$data.showSpinner = false; (this.$refs.password as HTMLElement).focus(); this.$store.commit('auth/logout'); if (!err.response) { this.$flash.error('There was an error with the network request. Please try again.'); return console.error(err); } const response = err.response; if (response.data && isObject(response.data.errors)) { response.data.errors.forEach((error: any) => { this.$flash.error(error.detail); }); } }); }, // Update the email address associated with the login form // so that it is populated in the parent model automatically. updateEmail: function (event: { target: HTMLInputElement }) { this.$emit('update-email', event.target.value); } }, template: `
{{ $t('auth.forgot_password.label') }}
`, });