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

113 lines
4.2 KiB
JavaScript
Raw Normal View History

2024-06-18 18:10:10 +00:00
import {createRouter, createWebHistory} from 'vue-router'
import store from '@/store';
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';
2023-08-14 13:42:26 +00:00
import HowTo from './views/HowTo';
2024-01-07 20:45:31 +00:00
import Login from '@/views/Login.vue';
import Register from '@/views/Register.vue';
2024-11-05 23:26:56 +00:00
import Dashboard from "@/views/admin/Dashboard.vue";
2024-01-07 20:45:31 +00:00
import Tickets from "@/views/Tickets.vue";
import Ticket from "@/views/Ticket.vue";
import Admin from "@/views/admin/Admin.vue";
import Empty from "@/views/Empty.vue";
import Events from "@/views/admin/Events.vue";
import AccessControl from "@/views/admin/AccessControl.vue";
2023-12-28 21:49:55 +00:00
import {default as BoxesAdmin} from "@/views/admin/Boxes.vue"
import Shipping from "@/views/admin/Shipping.vue";
const routes = [
2024-01-02 16:46:34 +00:00
{path: '/', redirect: '/37C3/items', meta: {requiresAuth: false}},
2024-01-07 20:45:31 +00:00
{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'}
},
{
2024-11-05 23:26:56 +00:00
path: '', name: 'admin', component: Dashboard, meta:
2024-01-07 20:45:31 +00:00
{requiresAuth: true, requiresPermission: 'delete_event'}
},
{
path: 'users/', name: 'users', component: AccessControl, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
2024-01-07 22:03:22 +00:00
},
{
path: 'boxes/', name: 'admin_boxes', component: BoxesAdmin, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
2024-01-07 20:45:31 +00:00
},
{
path: 'shipping/', name: 'shipping', component: Shipping, meta:
{requiresAuth: true, requiresPermission: 'delete_event'}
},
2024-01-07 20:45:31 +00:00
]
},
{path: '/user', name: 'user', component: Empty, meta: {requiresAuth: true}},
];
2024-06-18 18:10:10 +00:00
const router = createRouter({
history: createWebHistory(),
linkActiveClass: "active",
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) => {
2024-06-18 18:10:10 +00:00
if (to.params.event && to.params.event !== store.state.lastEvent) {
2024-01-07 20:45:31 +00:00
//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;