From 26a342c5a56ce9295aa4cc034e028f44e63369c2 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 18 Feb 2020 13:32:17 +0100 Subject: [PATCH] Fix license verification flow --- client/src/graphql/gql/mutations/login.gql | 1 + client/src/main.js | 3 ++- client/src/pages/email-verification.vue | 8 +++++++- client/src/pages/license-activation.vue | 5 ++++- client/src/pages/login.vue | 8 ++++++-- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/client/src/graphql/gql/mutations/login.gql b/client/src/graphql/gql/mutations/login.gql index ff107cce..e1f9d7d1 100644 --- a/client/src/graphql/gql/mutations/login.gql +++ b/client/src/graphql/gql/mutations/login.gql @@ -1,6 +1,7 @@ mutation Login($input: LoginInput!) { login(input: $input) { success + message errors { field } diff --git a/client/src/main.js b/client/src/main.js index 1bb58bd1..c177d063 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -153,12 +153,13 @@ router.beforeEach(async (to, from, next) => { next({name: 'login'}); return; } - getCookieValue('loginStatus') + if (unauthorizedAccess(to)) { const redirectUrl = `/login?redirect=${to.path}`; next(redirectUrl); return; } + if ((to.name !== 'noClass' && to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) { next({name: 'noClass'}) return; diff --git a/client/src/pages/email-verification.vue b/client/src/pages/email-verification.vue index 0f170bd5..f1da948a 100644 --- a/client/src/pages/email-verification.vue +++ b/client/src/pages/email-verification.vue @@ -50,7 +50,13 @@ export default { this.loading = false; if (data.registration.success) { this.keyValid = true; - this.$router.push('/'); + + if (data.registration.message === 'no_valid_license') { + this.$router.push({name: 'licenseActivation'}); + } else { + this.$router.push('/'); + } + } else { switch (data.registration.errors[0].field) { case 'invalid_key': diff --git a/client/src/pages/license-activation.vue b/client/src/pages/license-activation.vue index 689dc722..a3068a37 100644 --- a/client/src/pages/license-activation.vue +++ b/client/src/pages/license-activation.vue @@ -101,7 +101,10 @@ export default { coupon: '', couponErrors: [], loginError: '', - submitted: false + submitted: false, + me: { + email: '' + } }; }, diff --git a/client/src/pages/login.vue b/client/src/pages/login.vue index 860dd6e0..99535351 100644 --- a/client/src/pages/login.vue +++ b/client/src/pages/login.vue @@ -90,8 +90,12 @@ export default { ) { try { if (login.success) { - const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'; - that.$router.push(redirectUrl); + if (login.message === 'no_valid_license') { + that.$router.push({name: 'licenseActivation'}) + } else { + const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/'; + that.$router.push(redirectUrl); + } } else { const firstError = login.errors[0]; switch (firstError.field) {