2018-12-16 23:29:44 +00:00
|
|
|
import VueRouter, {Route} from 'vue-router';
|
2018-06-16 21:05:39 +00:00
|
|
|
import store from './store/index';
|
2018-07-16 00:09:53 +00:00
|
|
|
|
2018-06-16 21:05:39 +00:00
|
|
|
const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default;
|
|
|
|
|
|
|
|
// Base Vuejs Templates
|
2018-12-29 23:51:13 +00:00
|
|
|
import Login from './components/auth/Login.vue';
|
2018-12-30 01:00:50 +00:00
|
|
|
import Dashboard from './components/dashboard/Dashboard.vue';
|
|
|
|
import Account from './components/dashboard/Account.vue';
|
|
|
|
import ResetPassword from './components/auth/ResetPassword.vue';
|
2018-07-15 05:42:58 +00:00
|
|
|
import User from './models/user';
|
2018-07-16 02:03:38 +00:00
|
|
|
import {
|
|
|
|
Server,
|
|
|
|
ServerAllocations,
|
2018-07-21 05:34:30 +00:00
|
|
|
ConsolePage,
|
2018-08-04 04:32:50 +00:00
|
|
|
FileManagerPage,
|
2018-08-22 04:47:01 +00:00
|
|
|
DatabasesPage,
|
2018-07-16 02:03:38 +00:00
|
|
|
ServerSchedules,
|
|
|
|
ServerSettings,
|
2018-12-16 23:29:44 +00:00
|
|
|
ServerSubusers,
|
2018-07-16 02:03:38 +00:00
|
|
|
} from './components/server';
|
2018-06-16 21:05:39 +00:00
|
|
|
|
|
|
|
const routes = [
|
2018-07-16 00:09:53 +00:00
|
|
|
{name: 'login', path: '/auth/login', component: Login},
|
|
|
|
{name: 'forgot-password', path: '/auth/password', component: Login},
|
|
|
|
{name: 'checkpoint', path: '/auth/checkpoint', component: Login},
|
2018-06-16 21:05:39 +00:00
|
|
|
{
|
|
|
|
name: 'reset-password',
|
|
|
|
path: '/auth/password/reset/:token',
|
|
|
|
component: ResetPassword,
|
2018-12-16 23:29:44 +00:00
|
|
|
props: function (route: Route) {
|
2018-07-16 00:09:53 +00:00
|
|
|
return {token: route.params.token, email: route.query.email || ''};
|
2018-12-16 23:29:44 +00:00
|
|
|
},
|
2018-06-16 21:05:39 +00:00
|
|
|
},
|
|
|
|
|
2018-07-16 00:09:53 +00:00
|
|
|
{name: 'dashboard', path: '/', component: Dashboard},
|
|
|
|
{name: 'account', path: '/account', component: Account},
|
|
|
|
{name: 'account.api', path: '/account/api', component: Account},
|
|
|
|
{name: 'account.security', path: '/account/security', component: Account},
|
2018-06-16 21:05:39 +00:00
|
|
|
|
2018-12-16 23:29:44 +00:00
|
|
|
{
|
|
|
|
path: '/server/:id', component: Server,
|
2018-07-16 02:03:38 +00:00
|
|
|
children: [
|
2018-12-16 23:29:44 +00:00
|
|
|
{name: 'server', path: '', component: ConsolePage},
|
|
|
|
{name: 'server-files', path: 'files/:path(.*)?', component: FileManagerPage},
|
|
|
|
{name: 'server-subusers', path: 'subusers', component: ServerSubusers},
|
|
|
|
{name: 'server-schedules', path: 'schedules', component: ServerSchedules},
|
|
|
|
{name: 'server-databases', path: 'databases', component: DatabasesPage},
|
|
|
|
{name: 'server-allocations', path: 'allocations', component: ServerAllocations},
|
|
|
|
{name: 'server-settings', path: 'settings', component: ServerSettings},
|
|
|
|
],
|
|
|
|
},
|
2018-06-16 21:05:39 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const router = new VueRouter({
|
2018-12-16 23:29:44 +00:00
|
|
|
mode: 'history', routes,
|
2018-06-16 21:05:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Redirect the user to the login page if they try to access a protected route and
|
|
|
|
// have no JWT or the JWT is expired and wouldn't be accepted by the Panel.
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.path === route('auth.logout')) {
|
|
|
|
return window.location = route('auth.logout');
|
|
|
|
}
|
|
|
|
|
|
|
|
const user = store.getters['auth/getUser'];
|
|
|
|
|
2018-07-15 05:42:58 +00:00
|
|
|
// Check that if we're accessing a non-auth route that a user exists on the page.
|
|
|
|
if (!to.path.startsWith('/auth') && !(user instanceof User)) {
|
|
|
|
store.commit('auth/logout');
|
|
|
|
return window.location = route('auth.logout');
|
2018-06-16 21:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Continue on through the pipeline.
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
|
|
|
|
export default router;
|