2018-04-01 22:46:16 +00:00
|
|
|
<template>
|
|
|
|
<form class="bg-white shadow-lg rounded-lg pt-10 px-8 pb-6 mb-4 animate fadein" method="post"
|
|
|
|
v-on:submit.prevent="submitToken"
|
|
|
|
>
|
|
|
|
<div class="flex flex-wrap -mx-3 mb-6">
|
|
|
|
<div class="input-open">
|
2018-05-26 20:06:41 +00:00
|
|
|
<input class="input" id="grid-code" type="number" name="token" aria-labelledby="grid-username" required
|
|
|
|
ref="code"
|
|
|
|
:class="{ 'has-content' : code.length > 0 }"
|
2018-04-01 22:46:16 +00:00
|
|
|
v-model="code"
|
|
|
|
/>
|
|
|
|
<label for="grid-code">{{ $t('auth.two_factor.label') }}</label>
|
|
|
|
<p class="text-grey-darker text-xs">{{ $t('auth.two_factor.label_help') }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button class="btn btn-blue btn-jumbo" type="submit">
|
|
|
|
{{ $t('auth.sign_in') }}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="pt-6 text-center">
|
|
|
|
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark"
|
2018-04-08 20:46:32 +00:00
|
|
|
:to="{ name: 'login' }"
|
|
|
|
>
|
2018-04-01 22:46:16 +00:00
|
|
|
Back to Login
|
|
|
|
</router-link>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: "two-factor-form",
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
code: '',
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted: function () {
|
2018-06-03 00:01:54 +00:00
|
|
|
if ((this.$route.query.token || '').length < 1) {
|
|
|
|
return this.$router.push({ name: 'login' });
|
|
|
|
}
|
|
|
|
|
2018-04-01 22:46:16 +00:00
|
|
|
this.$refs.code.focus();
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
submitToken: function () {
|
|
|
|
const self = this;
|
|
|
|
|
2018-05-26 21:50:38 +00:00
|
|
|
self.clearFlashes();
|
2018-04-08 20:18:13 +00:00
|
|
|
axios.post(this.route('auth.login-checkpoint'), {
|
2018-04-01 22:46:16 +00:00
|
|
|
confirmation_token: this.$route.query.token,
|
|
|
|
authentication_code: this.$data.code,
|
|
|
|
})
|
|
|
|
.then(function (response) {
|
2018-06-02 23:59:16 +00:00
|
|
|
if (!(response.data instanceof Object)) {
|
|
|
|
throw new Error('An error was encountered while processing this login.');
|
|
|
|
}
|
|
|
|
|
2018-05-28 19:48:42 +00:00
|
|
|
localStorage.setItem('token', response.data.token);
|
|
|
|
self.$store.dispatch('login');
|
2018-06-03 00:12:45 +00:00
|
|
|
|
2018-04-01 22:46:16 +00:00
|
|
|
window.location = response.data.intended;
|
|
|
|
})
|
|
|
|
.catch(function (err) {
|
2018-05-28 19:48:42 +00:00
|
|
|
self.$store.dispatch('logout');
|
2018-04-01 22:46:16 +00:00
|
|
|
if (!err.response) {
|
|
|
|
return console.error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = err.response;
|
|
|
|
if (response.data && _.isObject(response.data.errors)) {
|
2018-05-26 21:50:38 +00:00
|
|
|
response.data.errors.forEach(function (error) {
|
|
|
|
self.error(error.detail);
|
|
|
|
});
|
2018-04-01 22:46:16 +00:00
|
|
|
self.$router.push({ name: 'login' });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|