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() {
const [firstRoute] = this.$route.matched
return firstRoute.name === 'index'
return firstRoute && firstRoute.name === 'index'
},
},
watch: {

View File

@ -1,5 +1,4 @@
import isEmpty from 'lodash/isEmpty'
import { VERSION } from '~/pages/terms-and-conditions'
export default async ({ store, env, route, redirect }) => {
let publicPages = env.publicPages
@ -10,14 +9,7 @@ export default async ({ store, env, route, redirect }) => {
// await store.dispatch('auth/refreshJWT', 'authenticated middleware')
const isAuthenticated = await store.dispatch('auth/check')
// 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) {
if (isAuthenticated === true) {
return true
}
@ -26,14 +18,9 @@ export default async ({ store, env, route, redirect }) => {
// set the redirect path for after the login
let params = {}
if (!isEmpty(route.path) && route.path !== '/' && route.path !== 'terms-and-conditions-confirm') {
if (!isEmpty(route.path) && route.path !== '/') {
params.path = route.path
}
console.log("ÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖÖö")
if (!upToDate) {
console.log("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
return redirect('/terms-and-conditions-confirm', params)
} else {
return redirect('/login', params)
}
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: {
middleware: ['authenticated'],
middleware: ['authenticated', 'termsAndConditions'],
linkActiveClass: 'router-link-active',
linkExactActiveClass: 'router-link-exact-active',
scrollBehavior: (to, _from, savedPosition) => {

View File

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

View File

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