Former-commit-id: 6523e78400ba84510f754e05f589b8f7c779319f [formerly 2d473b45716aaf6e35f2757bf9dc27adcafefd88] [formerly 5b34db9a57e050b307f1c5803cad82d2af155867 [formerly c206bea84a3e667047920d7dbcd0fc1c89cbced9]] Former-commit-id: 703d059a7455131dfa20d89050c40367f692b4b5 [formerly a320aa2603c47685e484cae3715eb788b1218fe9] Former-commit-id: 3819065ec37278f32ebceeda9cbb7af6f8723392
142 lines
2.9 KiB
JavaScript
142 lines
2.9 KiB
JavaScript
import Vue from 'vue'
|
|
import Router from 'vue-router'
|
|
import Login from '@/components/Login'
|
|
import Main from '@/components/Main'
|
|
import Files from '@/components/Files'
|
|
import Users from '@/components/Users'
|
|
import User from '@/components/User'
|
|
import Settings from '@/components/Settings'
|
|
import error403 from '@/components/errors/403'
|
|
import error404 from '@/components/errors/404'
|
|
import error500 from '@/components/errors/500'
|
|
import auth from '@/utils/auth.js'
|
|
import store from '@/store'
|
|
|
|
Vue.use(Router)
|
|
|
|
const router = new Router({
|
|
base: document.querySelector('meta[name="base"]').getAttribute('content'),
|
|
mode: 'history',
|
|
routes: [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: Login,
|
|
beforeEnter: function (to, from, next) {
|
|
auth.loggedIn()
|
|
.then(() => {
|
|
next({ path: '/files' })
|
|
})
|
|
.catch(() => {
|
|
document.title = 'Login'
|
|
next()
|
|
})
|
|
}
|
|
},
|
|
{
|
|
path: '/',
|
|
redirect: {
|
|
path: '/files/'
|
|
}
|
|
},
|
|
{
|
|
path: '/*',
|
|
component: Main,
|
|
meta: {
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: '/files/*',
|
|
name: 'Files',
|
|
component: Files
|
|
},
|
|
{
|
|
path: '/settings',
|
|
name: 'Settings',
|
|
component: Settings
|
|
},
|
|
{
|
|
path: '/403',
|
|
name: 'Forbidden',
|
|
component: error403
|
|
},
|
|
{
|
|
path: '/404',
|
|
name: 'Not Found',
|
|
component: error404
|
|
},
|
|
{
|
|
path: '/500',
|
|
name: 'Internal Server Error',
|
|
component: error500
|
|
},
|
|
{
|
|
path: '/users',
|
|
name: 'Users',
|
|
component: Users,
|
|
meta: {
|
|
requiresAdmin: true
|
|
}
|
|
},
|
|
{
|
|
path: '/users/',
|
|
redirect: {
|
|
path: '/users'
|
|
}
|
|
},
|
|
{
|
|
path: '/users/*',
|
|
name: 'User',
|
|
component: User,
|
|
meta: {
|
|
requiresAdmin: true
|
|
}
|
|
},
|
|
{
|
|
path: '/*',
|
|
redirect: {
|
|
name: 'Files'
|
|
}
|
|
}
|
|
]
|
|
}
|
|
]
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
if (to.matched.some(record => record.meta.requiresAuth)) {
|
|
// this route requires auth, check if logged in
|
|
// if not, redirect to login page.
|
|
auth.loggedIn()
|
|
.then(() => {
|
|
if (to.matched.some(record => record.meta.requiresAdmin)) {
|
|
if (store.state.user.admin) {
|
|
next()
|
|
return
|
|
}
|
|
|
|
next({
|
|
path: '/403'
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
next()
|
|
})
|
|
.catch(e => {
|
|
next({
|
|
path: '/login',
|
|
query: { redirect: to.fullPath }
|
|
})
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
export default router
|