2018-03-31 15:52:11 -05:00
|
|
|
<template>
|
|
|
|
<div>
|
2018-04-01 17:46:16 -05:00
|
|
|
<form class="bg-white shadow-lg rounded-lg pt-10 px-8 pb-6 mb-4 animate fadein" method="post"
|
2018-04-07 16:17:51 -05:00
|
|
|
v-on:submit.prevent="submitForm"
|
2018-04-01 17:46:16 -05:00
|
|
|
>
|
2018-03-31 15:52:11 -05:00
|
|
|
<div class="flex flex-wrap -mx-3 mb-6">
|
|
|
|
<div class="input-open">
|
2018-04-07 16:17:51 -05:00
|
|
|
<input class="input" id="grid-username" type="text" name="user" aria-labelledby="grid-username" required
|
2018-04-01 17:46:16 -05:00
|
|
|
ref="email"
|
2018-05-26 13:06:41 -07:00
|
|
|
:class="{ 'has-content' : user.email.length > 0 }"
|
|
|
|
:readonly="showSpinner"
|
|
|
|
:value="user.email"
|
2018-03-31 15:52:11 -05:00
|
|
|
v-on:input="updateEmail($event)"
|
|
|
|
/>
|
2018-03-31 16:33:10 -05:00
|
|
|
<label for="grid-username">{{ $t('strings.user_identifier') }}</label>
|
2018-03-31 15:52:11 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-wrap -mx-3 mb-6">
|
|
|
|
<div class="input-open">
|
2018-05-26 13:06:41 -07:00
|
|
|
<input class="input" id="grid-password" type="password" name="password" aria-labelledby="grid-password" required
|
2018-04-07 16:17:51 -05:00
|
|
|
ref="password"
|
2018-05-26 13:06:41 -07:00
|
|
|
:class="{ 'has-content' : user.password && user.password.length > 0 }"
|
|
|
|
:readonly="showSpinner"
|
2018-04-01 17:46:16 -05:00
|
|
|
v-model="user.password"
|
|
|
|
/>
|
2018-03-31 16:33:10 -05:00
|
|
|
<label for="grid-password">{{ $t('strings.password') }}</label>
|
2018-03-31 15:52:11 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
2018-04-07 16:17:51 -05:00
|
|
|
<button class="btn btn-blue btn-jumbo" type="submit" v-bind:disabled="showSpinner">
|
|
|
|
<span class="spinner white" v-bind:class="{ hidden: ! showSpinner }"> </span>
|
|
|
|
<span v-bind:class="{ hidden: showSpinner }">
|
|
|
|
{{ $t('auth.sign_in') }}
|
|
|
|
</span>
|
2018-03-31 15:52:11 -05:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="pt-6 text-center">
|
2018-04-01 17:46:16 -05:00
|
|
|
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark"
|
|
|
|
:to="{ name: 'forgot-password' }">
|
2018-04-08 15:18:13 -05:00
|
|
|
{{ $t('auth.forgot_password.label') }}
|
2018-03-31 15:52:11 -05:00
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'login-form',
|
|
|
|
props: {
|
2018-04-01 17:46:16 -05:00
|
|
|
user: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: function () {
|
|
|
|
return {
|
|
|
|
email: '',
|
|
|
|
password: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
}
|
2018-03-31 15:52:11 -05:00
|
|
|
},
|
2018-03-31 16:44:20 -05:00
|
|
|
data: function () {
|
|
|
|
return {
|
2018-04-01 17:46:16 -05:00
|
|
|
errors: [],
|
2018-04-07 16:17:51 -05:00
|
|
|
showSpinner: false,
|
2018-04-01 17:46:16 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted: function () {
|
|
|
|
this.$refs.email.focus();
|
2018-03-31 16:44:20 -05:00
|
|
|
},
|
2018-03-31 15:52:11 -05:00
|
|
|
methods: {
|
2018-04-01 17:46:16 -05:00
|
|
|
// Handle a login request eminating from the form. If 2FA is required the
|
|
|
|
// user will be presented with the 2FA modal window.
|
2018-04-07 16:17:51 -05:00
|
|
|
submitForm: function () {
|
2018-04-01 17:46:16 -05:00
|
|
|
const self = this;
|
2018-04-07 16:17:51 -05:00
|
|
|
this.$data.showSpinner = true;
|
2018-04-01 17:46:16 -05:00
|
|
|
|
2018-05-26 14:50:38 -07:00
|
|
|
this.clearFlashes();
|
2018-04-01 17:46:16 -05:00
|
|
|
axios.post(this.route('auth.login'), {
|
|
|
|
user: this.$props.user.email,
|
|
|
|
password: this.$props.user.password,
|
|
|
|
})
|
|
|
|
.then(function (response) {
|
|
|
|
if (response.data.complete) {
|
2018-05-28 12:48:42 -07:00
|
|
|
localStorage.setItem('token', response.data.token);
|
|
|
|
self.$store.dispatch('login');
|
|
|
|
return window.location = response.data.intended;
|
2018-04-01 17:46:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
self.$props.user.password = '';
|
2018-04-07 16:17:51 -05:00
|
|
|
self.$data.showSpinner = false;
|
2018-05-28 12:48:42 -07:00
|
|
|
self.$router.push({name: 'checkpoint', query: {token: response.data.login_token}});
|
2018-04-01 17:46:16 -05:00
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
self.$props.user.password = '';
|
2018-04-07 16:17:51 -05:00
|
|
|
self.$data.showSpinner = false;
|
2018-05-28 12:48:42 -07:00
|
|
|
self.$store.dispatch('logout');
|
|
|
|
|
2018-04-01 17:46:16 -05:00
|
|
|
if (!err.response) {
|
|
|
|
return console.error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = err.response;
|
|
|
|
if (response.data && _.isObject(response.data.errors)) {
|
2018-05-26 14:50:38 -07:00
|
|
|
response.data.errors.forEach(function (error) {
|
|
|
|
self.error(error.detail);
|
|
|
|
});
|
2018-04-07 16:17:51 -05:00
|
|
|
self.$refs.password.focus();
|
2018-04-01 17:46:16 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Update the email address associated with the login form
|
|
|
|
// so that it is populated in the parent model automatically.
|
2018-03-31 15:52:11 -05:00
|
|
|
updateEmail: function (event) {
|
|
|
|
this.$emit('update-email', event.target.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|