|
@@ -1,7 +1,7 @@
|
|
|
import Vue from 'vue';
|
|
|
import VueRouter from 'vue-router';
|
|
|
-
|
|
|
import App from './App.vue';
|
|
|
+import auth from './auth';
|
|
|
|
|
|
import NotFound from './components/404.vue';
|
|
|
import Home from './components/pages/Home.vue';
|
|
@@ -14,6 +14,32 @@ import Settings from './components/User/Settings.vue';
|
|
|
Vue.use(VueRouter);
|
|
|
|
|
|
let router = new VueRouter({ history: true });
|
|
|
+let _this = this;
|
|
|
+
|
|
|
+lofig.folder = '../config/default.json';
|
|
|
+
|
|
|
+lofig.get('socket.url', function(res) {
|
|
|
+ let socket = window.socket = io(window.location.protocol + '//' + res);
|
|
|
+ socket.on("ready", (status, role) => {
|
|
|
+ auth.data(status, role);
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
+router.beforeEach((transition) => {
|
|
|
+ if (transition.to.loginRequired || transition.to.adminRequired) {
|
|
|
+ auth.getStatus((authenticated, role) => {
|
|
|
+ if (transition.to.loginRequired && !authenticated) {
|
|
|
+ transition.redirect('/login')
|
|
|
+ } else if (transition.to.adminRequired && role !== 'admin') {
|
|
|
+ transition.redirect('/adminRequired');
|
|
|
+ } else {
|
|
|
+ transition.next();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ transition.next()
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
router.map({
|
|
|
'/': {
|
|
@@ -29,10 +55,12 @@ router.map({
|
|
|
component: User
|
|
|
},
|
|
|
'/settings': {
|
|
|
- component: Settings
|
|
|
+ component: Settings,
|
|
|
+ loginRequired: true
|
|
|
},
|
|
|
'/admin': {
|
|
|
- component: Admin
|
|
|
+ component: Admin,
|
|
|
+ adminRequired: true
|
|
|
},
|
|
|
'/official/:id': {
|
|
|
component: Station
|