Base attempt at using vuex to handle logins

This commit is contained in:
Dane Everitt 2018-06-05 23:00:01 -07:00
parent cc58bc9bd5
commit e948d81d8a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 218 additions and 202 deletions

View file

@ -77,32 +77,21 @@
this.$data.showSpinner = true;
this.clearFlashes();
axios.post(this.route('auth.login'), {
user: this.$props.user.email,
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.');
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;
}
if (response.data.complete) {
localStorage.setItem('token', response.data.token);
self.$store.dispatch('login');
return window.location = response.data.intended;
}
self.$props.user.password = '';
self.$data.showSpinner = false;
self.$router.push({name: 'checkpoint', query: {token: response.data.login_token}});
this.$props.user.password = '';
this.$data.showSpinner = false;
this.$router.push({name: 'checkpoint', query: {token: response.login_token}});
})
.catch(function (err) {
self.$props.user.password = '';
self.$data.showSpinner = false;
self.$refs.password.focus();
self.$store.dispatch('logout');
.catch(err => {
this.$props.user.password = '';
this.$data.showSpinner = false;
this.$refs.password.focus();
this.$store.dispatch('auth/logout');
if (!err.response) {
return console.error(err);

View file

@ -29,7 +29,7 @@
<script>
import { DateTime } from 'luxon';
import { ServerCollection } from '../../models/server';
import Server from '../../models/server';
import _ from 'lodash';
import Flash from '../Flash';
import ServerBox from './ServerBox';
@ -44,7 +44,7 @@
documentVisible: true,
loading: true,
search: '',
servers: new ServerCollection,
servers: [],
}
},
@ -83,14 +83,14 @@
this.clearFlashes();
})
.then(response => {
this.servers = new ServerCollection;
this.servers = [];
response.data.data.forEach(obj => {
this.getResourceUse(
this.servers.add(obj.attributes)
);
const s = new Server(obj.attributes);
this.servers.push(s);
this.getResourceUse(s);
});
if (this.servers.models.length === 0) {
if (this.servers.length === 0) {
this.info(this.$t('dashboard.index.no_matches'));
}
})