Merge branch 'feature/vuejs' into feature/vue-serverview
This commit is contained in:
commit
f2d2725ca0
130 changed files with 2275 additions and 1363 deletions
|
@ -1,20 +1,24 @@
|
|||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import { sync } from 'vuex-router-sync';
|
||||
import { serverModule } from "./modules/server";
|
||||
import { userModule } from './modules/user';
|
||||
import { authModule } from "./modules/auth";
|
||||
|
||||
const createStore = (router) => {
|
||||
const store = new Vuex.Store({
|
||||
strict: process.env.NODE_ENV !== 'production',
|
||||
modules: {
|
||||
userModule,
|
||||
serverModule,
|
||||
authModule,
|
||||
},
|
||||
});
|
||||
sync(store, router);
|
||||
return store;
|
||||
};
|
||||
Vue.use(Vuex);
|
||||
|
||||
export default createStore;
|
||||
const store = new Vuex.Store({
|
||||
strict: process.env.NODE_ENV !== 'production',
|
||||
modules: { userModule, serverModule, authModule },
|
||||
});
|
||||
|
||||
if (module.hot) {
|
||||
module.hot.accept(['./modules/auth'], () => {
|
||||
const newAuthModule = require('./modules/auth').default;
|
||||
|
||||
store.hotUpdate({
|
||||
modules: { newAuthModule },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default store;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
import User from './../../models/user';
|
||||
|
||||
const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').default;
|
||||
|
||||
export const authModule = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
user: User.fromToken(),
|
||||
user: typeof window.PterodactylUser === 'object' ? new User(window.PterodactylUser) : null,
|
||||
},
|
||||
getters: {
|
||||
/**
|
||||
|
@ -13,12 +14,20 @@ export const authModule = {
|
|||
* @param state
|
||||
* @returns {User|null}
|
||||
*/
|
||||
currentUser: function (state) {
|
||||
getUser: function (state) {
|
||||
return state.user;
|
||||
}
|
||||
},
|
||||
},
|
||||
setters: {},
|
||||
actions: {
|
||||
/**
|
||||
* Log a user into the Panel.
|
||||
*
|
||||
* @param commit
|
||||
* @param {String} user
|
||||
* @param {String} password
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
login: ({commit}, {user, password}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.post(route('auth.login'), {user, password})
|
||||
|
@ -32,7 +41,7 @@ export const authModule = {
|
|||
}
|
||||
|
||||
if (response.data.complete) {
|
||||
commit('login', {jwt: response.data.jwt});
|
||||
commit('login', response.data.user);
|
||||
return resolve({
|
||||
complete: true,
|
||||
intended: response.data.intended,
|
||||
|
@ -47,24 +56,40 @@ export const authModule = {
|
|||
.catch(reject);
|
||||
});
|
||||
},
|
||||
logout: function ({commit}) {
|
||||
|
||||
/**
|
||||
* Update a user's email address on the Panel and store the updated result in Vuex.
|
||||
*
|
||||
* @param commit
|
||||
* @param {String} email
|
||||
* @param {String} password
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
updateEmail: function ({commit}, {email, password}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(route('auth.logout'))
|
||||
.then(() => {
|
||||
commit('logout');
|
||||
window.axios.put(route('api.client.account.update-email'), {email, password})
|
||||
.then(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) && response.status !== 201) {
|
||||
return reject(new Error('An error was encountered while processing this request.'));
|
||||
}
|
||||
|
||||
commit('setEmail', email);
|
||||
return resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
})
|
||||
});
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
login: function (state, {jwt}) {
|
||||
localStorage.setItem('token', jwt);
|
||||
state.user = User.fromToken(jwt);
|
||||
setEmail: function (state, email) {
|
||||
state.user.email = email;
|
||||
},
|
||||
login: function (state, data) {
|
||||
state.user = new User(data);
|
||||
},
|
||||
logout: function (state) {
|
||||
localStorage.removeItem('token');
|
||||
state.user = null;
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue