Merge branch 'feature/vuejs' into feature/vuejs-serverlist

This commit is contained in:
Dane Everitt 2018-06-02 17:12:45 -07:00
commit 6b2649ad2c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
18 changed files with 482 additions and 12 deletions

View file

@ -17,8 +17,8 @@ try {
*/
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.headers.common['Accept'] = 'application/json';
window.axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.token || '';
if (typeof phpdebugbar !== 'undefined') {

View file

@ -5,13 +5,14 @@
>
<div class="flex flex-wrap -mx-3 mb-6">
<div class="input-open">
<input class="input" id="grid-email" type="email" aria-labelledby="grid-email" ref="email" required
<input class="input" id="grid-email" type="email" aria-labelledby="grid-email-label" required
ref="email"
v-bind:class="{ 'has-content': email.length > 0 }"
v-bind:readonly="showSpinner"
v-bind:value="email"
v-on:input="updateEmail($event)"
/>
<label for="grid-email">{{ $t('strings.email') }}</label>
<label for="grid-email" id="grid-email-label">{{ $t('strings.email') }}</label>
<p class="text-grey-darker text-xs">{{ $t('auth.forgot_password.label_help') }}</p>
</div>
</div>
@ -25,6 +26,7 @@
</div>
<div class="pt-6 text-center">
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark"
aria-label="Go to login"
:to="{ name: 'login' }"
>
{{ $t('auth.go_to_login') }}
@ -68,6 +70,10 @@
email: this.$props.email,
})
.then(function (response) {
if (!(response.data instanceof Object)) {
throw new Error('An error was encountered while processing this request.');
}
self.$data.submitDisabled = false;
self.$data.showSpinner = false;
self.success(response.data.status);

View file

@ -5,29 +5,30 @@
>
<div class="flex flex-wrap -mx-3 mb-6">
<div class="input-open">
<input class="input" id="grid-username" type="text" name="user" aria-labelledby="grid-username" required
<input class="input" id="grid-username" type="text" name="user" aria-labelledby="grid-username-label" required
ref="email"
:class="{ 'has-content' : user.email.length > 0 }"
:readonly="showSpinner"
:value="user.email"
v-on:input="updateEmail($event)"
/>
<label for="grid-username">{{ $t('strings.user_identifier') }}</label>
<label id="grid-username-label" for="grid-username">{{ $t('strings.user_identifier') }}</label>
</div>
</div>
<div class="flex flex-wrap -mx-3 mb-6">
<div class="input-open">
<input class="input" id="grid-password" type="password" name="password" aria-labelledby="grid-password" required
<input class="input" id="grid-password" type="password" name="password" aria-labelledby="grid-password-label" required
ref="password"
:class="{ 'has-content' : user.password && user.password.length > 0 }"
:readonly="showSpinner"
v-model="user.password"
/>
<label for="grid-password">{{ $t('strings.password') }}</label>
<label id="grid-password-label" for="grid-password">{{ $t('strings.password') }}</label>
</div>
</div>
<div>
<button class="btn btn-blue btn-jumbo" type="submit" v-bind:disabled="showSpinner">
<button id="grid-login-button" class="btn btn-blue btn-jumbo" type="submit" aria-label="Log in"
v-bind:disabled="showSpinner">
<span class="spinner white" v-bind:class="{ hidden: ! showSpinner }">&nbsp;</span>
<span v-bind:class="{ hidden: showSpinner }">
{{ $t('auth.sign_in') }}
@ -35,7 +36,7 @@
</button>
</div>
<div class="pt-6 text-center">
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark"
<router-link class="text-xs text-grey tracking-wide no-underline uppercase hover:text-grey-dark" aria-label="Forgot password"
:to="{ name: 'forgot-password' }">
{{ $t('auth.forgot_password.label') }}
</router-link>
@ -81,6 +82,12 @@
password: this.$props.user.password,
})
.then(function (response) {
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
// in JSON format) throw an error and don't try to continue with the login.
if (!(response.data instanceof Object)) {
throw new Error('An error was encountered while processing this request.');
}
if (response.data.complete) {
localStorage.setItem('token', response.data.token);
self.$store.dispatch('login');
@ -94,6 +101,7 @@
.catch(function (err) {
self.$props.user.password = '';
self.$data.showSpinner = false;
self.$refs.password.focus();
self.$store.dispatch('logout');
if (!err.response) {
@ -105,7 +113,6 @@
response.data.errors.forEach(function (error) {
self.error(error.detail);
});
self.$refs.password.focus();
}
});
},

View file

@ -93,6 +93,10 @@
token: this.$props.token,
})
.then(function (response) {
if (!(response.data instanceof Object)) {
throw new Error('An error was encountered while processing this login.');
}
return window.location = response.data.redirect_to;
})
.catch(function (err) {

View file

@ -37,6 +37,10 @@
};
},
mounted: function () {
if ((this.$route.query.token || '').length < 1) {
return this.$router.push({ name: 'login' });
}
this.$refs.code.focus();
},
methods: {
@ -49,8 +53,13 @@
authentication_code: this.$data.code,
})
.then(function (response) {
if (!(response.data instanceof Object)) {
throw new Error('An error was encountered while processing this login.');
}
localStorage.setItem('token', response.data.token);
self.$store.dispatch('login');
window.location = response.data.intended;
})
.catch(function (err) {

View file

@ -7,7 +7,7 @@ import ResetPassword from './components/auth/ResetPassword';
export const routes = [
{ name: 'login', path: '/auth/login', component: Login },
{ name: 'forgot-password', path: '/auth/password', component: Login },
{ name: 'checkpoint', path: '/checkpoint', component: Login },
{ name: 'checkpoint', path: '/auth/checkpoint', component: Login },
{
name: 'reset-password',
path: '/auth/password/reset/:token',