Implement accept terms and conditions flow

This commit is contained in:
roschaefer 2019-08-21 14:52:41 +02:00 committed by ogerly
parent 592a682bd7
commit 036e2605b7
6 changed files with 34 additions and 28 deletions

View File

@ -224,7 +224,7 @@ export default {
}, },
showFilterPostsDropdown() { showFilterPostsDropdown() {
const [firstRoute] = this.$route.matched const [firstRoute] = this.$route.matched
return firstRoute.name === 'index' return firstRoute && firstRoute.name === 'index'
}, },
}, },
watch: { watch: {

View File

@ -1,5 +1,4 @@
import isEmpty from 'lodash/isEmpty' import isEmpty from 'lodash/isEmpty'
import { VERSION } from '~/pages/terms-and-conditions'
export default async ({ store, env, route, redirect }) => { export default async ({ store, env, route, redirect }) => {
let publicPages = env.publicPages let publicPages = env.publicPages
@ -10,14 +9,7 @@ export default async ({ store, env, route, redirect }) => {
// await store.dispatch('auth/refreshJWT', 'authenticated middleware') // await store.dispatch('auth/refreshJWT', 'authenticated middleware')
const isAuthenticated = await store.dispatch('auth/check') const isAuthenticated = await store.dispatch('auth/check')
if (isAuthenticated === true) {
// TODO: find a better solution to **reliably** get the user
// having the encrypted JWT does not mean we have access to the user object
const user = await store.getters['auth/user']
const upToDate = user.termsAndConditionsAgreedVersion === VERSION
if (isAuthenticated === true && upToDate) {
return true return true
} }
@ -26,14 +18,9 @@ export default async ({ store, env, route, redirect }) => {
// set the redirect path for after the login // set the redirect path for after the login
let params = {} let params = {}
if (!isEmpty(route.path) && route.path !== '/' && route.path !== 'terms-and-conditions-confirm') { if (!isEmpty(route.path) && route.path !== '/') {
params.path = route.path params.path = route.path
} }
console.log("ÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖö")
if (!upToDate) { return redirect('/login', params)
console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
return redirect('/terms-and-conditions-confirm', params)
} else {
return redirect('/login', params)
}
} }

View File

@ -0,0 +1,19 @@
import isEmpty from 'lodash/isEmpty'
export default async ({ store, env, route, redirect }) => {
let publicPages = env.publicPages
// only affect non public pages
if (publicPages.indexOf(route.name) >= 0) {
return true
}
if (route.name === 'terms-and-conditions-confirm') return true // avoid endless loop
if(store.getters['auth/termsAndConditionsAgreed']) return true
let params = {}
if (!isEmpty(route.path) && route.path !== '/') {
params.path = route.path
}
return redirect('/terms-and-conditions-confirm', params)
}

View File

@ -122,7 +122,7 @@ module.exports = {
], ],
router: { router: {
middleware: ['authenticated'], middleware: ['authenticated', 'termsAndConditions'],
linkActiveClass: 'router-link-active', linkActiveClass: 'router-link-active',
linkExactActiveClass: 'router-link-exact-active', linkExactActiveClass: 'router-link-exact-active',
scrollBehavior: (to, _from, savedPosition) => { scrollBehavior: (to, _from, savedPosition) => {

View File

@ -54,9 +54,6 @@ export default {
...mapGetters({ ...mapGetters({
currentUser: 'auth/user', currentUser: 'auth/user',
}), }),
...mapMutations({
setCurrentUser: 'auth/SET_USER',
}),
}, },
data() { data() {
return { return {
@ -74,15 +71,14 @@ export default {
} }
}, },
asyncData({ store, redirect }) { asyncData({ store, redirect }) {
console.log('store') if (store.getters['auth/termsAndConditionsAgreed']) {
console.log(store)
console.log('redirect')
console.log(redirect)
if (store.getters['auth/isLoggedIn']) {
redirect('/') redirect('/')
} }
}, },
methods: { methods: {
...mapMutations({
setCurrentUser: 'auth/SET_USER',
}),
async submit() { async submit() {
try { try {
await this.$apollo.mutate({ await this.$apollo.mutate({
@ -100,7 +96,7 @@ export default {
}, },
}) })
this.$toast.success(this.$t('DANKE')) this.$toast.success(this.$t('DANKE'))
this.$router.push('/') this.$router.replace(this.$route.query.path || '/')
} catch (err) { } catch (err) {
this.$toast.error(err.message) this.$toast.error(err.message)
} }

View File

@ -1,4 +1,5 @@
import gql from 'graphql-tag' import gql from 'graphql-tag'
import { VERSION } from '~/pages/terms-and-conditions'
export const state = () => { export const state = () => {
return { return {
@ -42,6 +43,9 @@ export const getters = {
token(state) { token(state) {
return state.token return state.token
}, },
termsAndConditionsAgreed(state) {
return state.user && state.user.termsAndConditionsAgreedVersion === VERSION
}
} }
export const actions = { export const actions = {