summaryrefslogtreecommitdiffstats
path: root/webapp/src
diff options
context:
space:
mode:
authorUdo Walter2018-08-04 05:45:18 +0200
committerUdo Walter2018-08-04 05:45:18 +0200
commit00d8421e8d7517c58a8aa5906c1273408c37a4fe (patch)
treea1bdcc7f46d4073fe3b7ff300ec6bde44eab1290 /webapp/src
parent[webapp/groups] bugfix + route to create group/client (diff)
downloadbas-00d8421e8d7517c58a8aa5906c1273408c37a4fe.tar.gz
bas-00d8421e8d7517c58a8aa5906c1273408c37a4fe.tar.xz
bas-00d8421e8d7517c58a8aa5906c1273408c37a4fe.zip
[webapp] login now redirect to the requested route
Diffstat (limited to 'webapp/src')
-rw-r--r--webapp/src/components/DashboardPage.vue3
-rw-r--r--webapp/src/components/LoginPage.vue10
-rw-r--r--webapp/src/main.js3
-rw-r--r--webapp/src/router.js31
-rw-r--r--webapp/src/store/global.js4
5 files changed, 33 insertions, 18 deletions
diff --git a/webapp/src/components/DashboardPage.vue b/webapp/src/components/DashboardPage.vue
index d400f9f..d9dfcb6 100644
--- a/webapp/src/components/DashboardPage.vue
+++ b/webapp/src/components/DashboardPage.vue
@@ -191,7 +191,7 @@ export default {
drawerOpen (value) { localStorage.setItem('drawerOpen', value) }
},
methods: {
- ...mapMutations(['shiftSnackbars']),
+ ...mapMutations(['shiftSnackbars', 'setLoginRedirect']),
toggleDrawer () {
if (this.settings.mini && this.desktop) this.drawerMini = !this.drawerMini
else this.drawerOpen = !this.drawerOpen
@@ -222,6 +222,7 @@ export default {
},
logout () {
this.$http.post('/api/logout').then(response => {
+ this.setLoginRedirect(this.$route.fullPath)
this.$router.push('/login')
})
}
diff --git a/webapp/src/components/LoginPage.vue b/webapp/src/components/LoginPage.vue
index dc77f68..0ff5d46 100644
--- a/webapp/src/components/LoginPage.vue
+++ b/webapp/src/components/LoginPage.vue
@@ -52,6 +52,7 @@ export default {
name: 'LoginPage',
data () {
return {
+ loginRedirect: null,
valid: true,
username: '',
usernameError: false,
@@ -79,7 +80,9 @@ export default {
if (this.$refs.form.validate()) {
this.$http.post('/api/login', { username: this.username, password: this.password })
.then(response => {
- this.$router.push('/dashboard')
+ const nextRoute = this.$store.state.loginRedirect
+ if (nextRoute) this.$router.replace(nextRoute)
+ else this.$router.replace({ name: 'dashboard' })
})
.catch(error => {
if (error.response.data.status === 'USER_NOTFOUND') {
@@ -91,6 +94,11 @@ export default {
})
}
}
+ },
+ watch: {
+ $route (v) {
+ console.log(v)
+ }
}
}
</script>
diff --git a/webapp/src/main.js b/webapp/src/main.js
index 7fd927a..4193481 100644
--- a/webapp/src/main.js
+++ b/webapp/src/main.js
@@ -6,7 +6,7 @@ import Vuex from 'vuex'
import globalStore from '@/store/global'
import storeModules from '@/config/store'
import axios from 'axios'
-import router from '@/router'
+import { router, registerRouterGuards } from '@/router'
import VueI18n from 'vue-i18n'
import i18nMessages from '@/config/i18n'
import '@/assets/styles.css'
@@ -19,6 +19,7 @@ Object.keys(storeModules).forEach(key => {
})
globalStore.modules = storeModules
var store = new Vuex.Store(globalStore)
+registerRouterGuards(store)
Vue.use(VueI18n)
diff --git a/webapp/src/router.js b/webapp/src/router.js
index 24e2348..9b432e5 100644
--- a/webapp/src/router.js
+++ b/webapp/src/router.js
@@ -21,12 +21,12 @@ var router = new Router({
routes: [
{
path: '/login',
- name: 'LoginPage',
+ name: 'login',
component: LoginPage
},
{
path: '/dashboard',
- name: 'Dashboard',
+ name: 'dashboard',
component: DashboardPage,
children: setChildren(dashboardModules.concat(DashboardPage.routes()), DashboardPage)
},
@@ -37,16 +37,19 @@ var router = new Router({
]
})
-router.beforeEach((to, from, next) => {
- var loggedIn = document.cookie.indexOf('jwt_hp') >= 0
- if (to.path === '/login') {
- if (loggedIn) next('/dashboard')
- else next()
- } else if (!loggedIn) {
- next('/login')
- } else {
- next()
- }
-})
+const registerRouterGuards = function (store) {
+ router.beforeEach((to, from, next) => {
+ const loggedIn = document.cookie.indexOf('jwt_hp') >= 0
+ if (to.name === 'login') {
+ if (loggedIn) next({ name: 'dashboard' })
+ else next()
+ } else if (!loggedIn) {
+ store.commit('setLoginRedirect', to.fullPath)
+ next({ name: 'login' })
+ } else {
+ next()
+ }
+ })
+}
-export default router
+export { router, registerRouterGuards }
diff --git a/webapp/src/store/global.js b/webapp/src/store/global.js
index d461ad9..bf31ce9 100644
--- a/webapp/src/store/global.js
+++ b/webapp/src/store/global.js
@@ -19,7 +19,8 @@ export default {
clipped: loadSetting('clipped', true),
mini: loadSetting('mini', true)
},
- snackbars: []
+ snackbars: [],
+ loginRedirect: null
},
getters: {
tabsDark: state => state.settings.dark || state.settings.coloredTabs,
@@ -31,6 +32,7 @@ export default {
}
},
mutations: {
+ setLoginRedirect: (state, value) => { state.loginRedirect = value },
saveSetting (state, { name, value }) { if (name in state.settings) state.settings[name] = value; localStorage.setItem('settings.' + name, value) },
shiftSnackbars (state) {
state.snackbars.shift()