c3lf-system-3/web/src/router.js

106 lines
3.7 KiB
JavaScript
Raw Normal View History

import Items from './views/Items';
2019-12-05 22:27:24 +00:00
import Boxes from './views/Boxes';
2019-12-24 13:02:56 +00:00
import Files from './views/Files';
2019-12-05 22:27:24 +00:00
import Error from './views/Error';
2023-08-14 13:42:26 +00:00
import HowTo from './views/HowTo';
import VueRouter from 'vue-router';
import Vue from 'vue';
2024-01-07 20:45:31 +00:00
import Login from '@/views/Login.vue';
import Register from '@/views/Register.vue';
import Debug from "@/views/admin/Debug.vue";
import Tickets from "@/views/Tickets.vue";
import Ticket from "@/views/Ticket.vue";
import Admin from "@/views/admin/Admin.vue";
import store from "@/store";
import Empty from "@/views/Empty.vue";
import Events from "@/views/admin/Events.vue";
import AccessControl from "@/views/admin/AccessControl.vue";
Vue.use(VueRouter);
const routes = [
2024-01-07 20:45:31 +00:00
{path: '/', redirect: '/Camp23/items', meta: {requiresAuth: false}},
{path: '/login/', name: 'login', component: Login, meta: {requiresAuth: false}},
{path: '/register/', name: 'register', component: Register, meta: {requiresAuth: false}},
{path: '/howto/', name: 'howto', component: HowTo, meta: {requiresAuth: true}},
{
path: '/:event/items/', name: 'items', component: Items, meta:
{requiresAuth: true, requiresPermission: 'view_item'}
},
{
path: '/:event/item/:uid/', name: 'item', component: Items, meta:
{requiresAuth: true, requiresPermission: 'view_item'}
},
{
path: '/:event/boxes/', name: 'boxes', component: Boxes, meta:
{requiresAuth: true, requiresPermission: 'view_container'}
},
{
path: '/:event/box/:uid/', name: 'box', component: Boxes, meta:
{requiresAuth: true, requiresPermission: 'view_container'}
},
{
path: '/:event/tickets/', name: 'tickets', component: Tickets, meta:
{requiresAuth: true, requiresPermission: 'view_issuethread'}
},
{
path: '/:event/ticket/:id/', name: 'ticket', component: Ticket, meta:
{requiresAuth: true, requiresPermission: 'view_issuethread'}
},
{
path: '/admin/', component: Admin, meta:
{requiresAuth: true, requiresPermission: 'delete_event'},
children: [
{
path: 'files/', name: 'files', component: Files, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'events/', name: 'events', component: Events, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: '', name: 'admin', component: Debug, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'users/', name: 'users', component: AccessControl, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
]
},
{path: '/user', name: 'user', component: Empty, meta: {requiresAuth: true}},
2023-11-27 00:14:52 +00:00
{path: '*', component: Error},
];
const router = new VueRouter({
2023-11-27 00:14:52 +00:00
mode: 'history',
2024-01-07 20:45:31 +00:00
routes,
});
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth && !store.getters.isLoggedIn) {
console.log("Not logged in, redirecting to login page")
next({
name: 'login',
query: {redirect: to.fullPath},
})
} else if (to.meta.requiresPermission && !store.getters.checkPermission(to.params.event || "*", to.meta.requiresPermission)) {
console.log("Not enough permissions, redirecting to empty page")
next({
path: '/user',
})
} else {
next()
}
});
router.afterEach((to/*, from*/) => {
if (to.params.event) {
//console.log('update last event', to.params.event);
store.commit('updateLastEvent', to.params.event);
}
});
2023-08-14 13:42:26 +00:00
export default router;