Add no-class page & guard
This commit is contained in:
parent
b20917d29a
commit
06dbf20094
|
|
@ -16,6 +16,7 @@ import veeDe from 'vee-validate/dist/locale/de';
|
||||||
import {dateFilter} from './filters/date-filter';
|
import {dateFilter} from './filters/date-filter';
|
||||||
import autoGrow from '@/directives/auto-grow'
|
import autoGrow from '@/directives/auto-grow'
|
||||||
import clickOutside from '@/directives/click-outside'
|
import clickOutside from '@/directives/click-outside'
|
||||||
|
import ME_QUERY from '@/graphql/gql/meQuery.gql';
|
||||||
|
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
|
|
@ -113,7 +114,7 @@ Vue.use(VeeValidate, {
|
||||||
|
|
||||||
Vue.filter('date', dateFilter);
|
Vue.filter('date', dateFilter);
|
||||||
|
|
||||||
/* logged in guard */
|
/* guards */
|
||||||
|
|
||||||
function getCookieValue(cookieName) {
|
function getCookieValue(cookieName) {
|
||||||
// https://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript
|
// https://stackoverflow.com/questions/5639346/what-is-the-shortest-function-for-reading-a-cookie-by-name-in-javascript
|
||||||
|
|
@ -121,18 +122,32 @@ function getCookieValue(cookieName) {
|
||||||
return cookieValue ? cookieValue.pop() : '';
|
return cookieValue ? cookieValue.pop() : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirectIfLoginRequird(to) {
|
function loginRequired(to) {
|
||||||
// public pages have the meta.public property set to true
|
// public pages have the meta.public property set to true
|
||||||
return (!to.hasOwnProperty('meta') || !to.meta.hasOwnProperty('public') || !to.meta.public) && getCookieValue('loginStatus') !== 'true';
|
return !to.hasOwnProperty('meta') || !to.meta.hasOwnProperty('public') || !to.meta.public;
|
||||||
}
|
}
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
function unauthorizedAccess(to) {
|
||||||
if (redirectIfLoginRequird(to)) {
|
return loginRequired(to) && getCookieValue('loginStatus') !== 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
function redirectStudentsWithoutClass() {
|
||||||
|
return privateApolloClient.query({
|
||||||
|
query: ME_QUERY,
|
||||||
|
}).then(({data}) => data.me.schoolClasses.edges.length === 0 && data.me.permissions.length === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
router.beforeEach(async (to, from, next) => {
|
||||||
|
if (unauthorizedAccess(to)) {
|
||||||
const redirectUrl = `/login?redirect=${to.path}`;
|
const redirectUrl = `/login?redirect=${to.path}`;
|
||||||
next(redirectUrl);
|
next(redirectUrl);
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (to.name !== 'noClass' && loginRequired(to) && await redirectStudentsWithoutClass()) {
|
||||||
|
router.push({name: 'noClass'})
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<p>Sie sind keiner Klasse zugeteilt. Bitte kontaktieren Sie die zuständige Lehrperson um Zugriff zu erhalten.</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -29,6 +29,7 @@ import styleGuidePage from '@/pages/styleguide'
|
||||||
import moduleRoom from '@/pages/moduleRoom'
|
import moduleRoom from '@/pages/moduleRoom'
|
||||||
import login from '@/pages/login'
|
import login from '@/pages/login'
|
||||||
import registration from '@/pages/registration'
|
import registration from '@/pages/registration'
|
||||||
|
import waitForClass from '@/pages/waitForClass'
|
||||||
|
|
||||||
import store from '@/store/index';
|
import store from '@/store/index';
|
||||||
|
|
||||||
|
|
@ -127,6 +128,12 @@ const routes = [
|
||||||
layout: 'public',
|
layout: 'public',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/no-class',
|
||||||
|
component: waitForClass,
|
||||||
|
name: 'noClass',
|
||||||
|
meta: {layout: 'public'}
|
||||||
|
},
|
||||||
{path: '/styleguide', component: styleGuidePage},
|
{path: '/styleguide', component: styleGuidePage},
|
||||||
{path: '*', component: p404}
|
{path: '*', component: p404}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue