Redirect users without license to coupon page
This commit is contained in:
parent
26a342c5a5
commit
f3bd38e819
|
|
@ -7,6 +7,7 @@ fragment UserParts on UserNode {
|
||||||
firstName
|
firstName
|
||||||
lastName
|
lastName
|
||||||
avatarUrl
|
avatarUrl
|
||||||
|
licenseExpiryDate
|
||||||
lastModule {
|
lastModule {
|
||||||
id
|
id
|
||||||
slug
|
slug
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,12 @@ function unauthorizedAccess(to) {
|
||||||
return loginRequired(to) && getCookieValue('loginStatus') !== 'true';
|
return loginRequired(to) && getCookieValue('loginStatus') !== 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function redirectUsersWithoutValidLicense(to) {
|
||||||
|
return privateApolloClient.query({
|
||||||
|
query: ME_QUERY,
|
||||||
|
}).then(({data}) => data.me.licenseExpiryDate.edges.length == null);
|
||||||
|
}
|
||||||
|
|
||||||
function redirectStudentsWithoutClass() {
|
function redirectStudentsWithoutClass() {
|
||||||
return privateApolloClient.query({
|
return privateApolloClient.query({
|
||||||
query: ME_QUERY,
|
query: ME_QUERY,
|
||||||
|
|
@ -147,7 +153,6 @@ function networkErrorCallback(statusCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
// handle logout
|
|
||||||
if (to.path === '/logout') {
|
if (to.path === '/logout') {
|
||||||
privateApolloClient.resetStore();
|
privateApolloClient.resetStore();
|
||||||
next({name: 'login'});
|
next({name: 'login'});
|
||||||
|
|
@ -160,6 +165,12 @@ router.beforeEach(async (to, from, next) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (to.name !== 'licenseActivation' && redirectUsersWithoutValidLicense()) {
|
||||||
|
next({name: 'licenseActivation'})
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle users students without class
|
||||||
if ((to.name !== 'noClass' && to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
|
if ((to.name !== 'noClass' && to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
|
||||||
next({name: 'noClass'})
|
next({name: 'noClass'})
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class UserNode(DjangoObjectType):
|
||||||
model = User
|
model = User
|
||||||
filter_fields = ['username', 'email']
|
filter_fields = ['username', 'email']
|
||||||
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module', 'avatar_url',
|
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module', 'avatar_url',
|
||||||
'selected_class']
|
'selected_class', 'license_expiry_date']
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
|
|
||||||
def resolve_pk(self, info, **kwargs):
|
def resolve_pk(self, info, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue