Mercurial > gemma
annotate client/src/router.js @ 1191:b23622905a3f
switched entirely to sass instead of scss
for cleaner code/less lines, just removed all ; and {}
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 16 Nov 2018 14:37:07 +0100 |
parents | 1d4801145a2d |
children | 162a790120c2 |
rev | line source |
---|---|
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
1 /* |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
2 * This is Free Software under GNU Affero General Public License v >= 3.0 |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
3 * without warranty, see README.md and license for details. |
1142
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
4 * |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
5 * SPDX-License-Identifier: AGPL-3.0-or-later |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
6 * License-Filename: LICENSES/AGPL-3.0.txt |
1142
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
7 * |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
8 * Copyright (C) 2018 by via donau |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
9 * – Österreichische Wasserstraßen-Gesellschaft mbH |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
10 * Software engineering by Intevation GmbH |
1142
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
11 * |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
12 * Author(s): |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
13 * Thomas Junk <thomas.junk@intevation.de> |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
14 */ |
3 | 15 import Vue from "vue"; |
16 import Router from "vue-router"; | |
17 import store from "./store"; | |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
581
diff
changeset
|
18 import { |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
581
diff
changeset
|
19 sessionStillActive, |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
581
diff
changeset
|
20 toMillisFromString |
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
581
diff
changeset
|
21 } from "./application/lib/session"; |
3 | 22 |
483
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
466
diff
changeset
|
23 /* facilitate codesplitting */ |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
581
diff
changeset
|
24 const Login = () => import("./login/Login.vue"); |
592
8e67604d972a
moved main.vue to application
Thomas Junk <thomas.junk@intevation.de>
parents:
585
diff
changeset
|
25 const Main = () => import("./application/Main.vue"); |
585
ef307bd6b5d8
refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
581
diff
changeset
|
26 const Usermanagement = () => import("./usermanagement/Usermanagement.vue"); |
713
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
27 const Logs = () => import("./logs/logs.vue"); |
1173 | 28 const Importqueue = () => import("./importqueue/Importqueue.vue"); |
853 | 29 const Systemconfiguration = () => |
30 import("./systemconfiguration/systemconfiguration.vue"); | |
466
e3035621cc52
refac: Small improvement of loading time with code splitting
Thomas Junk <thomas.junk@intevation.de>
parents:
285
diff
changeset
|
31 |
3 | 32 Vue.use(Router); |
33 | |
34 const router = new Router({ | |
35 routes: [ | |
36 { | |
6 | 37 path: "/login", |
3 | 38 name: "login", |
39 component: Login | |
40 }, | |
41 { | |
581 | 42 path: "/usermanagement", |
43 name: "usermanagement", | |
44 component: Usermanagement, | |
278
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
45 meta: { |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
46 requiresAuth: true |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
47 }, |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
48 beforeEnter: (to, from, next) => { |
285
8e22d1f16f81
refactor: better variable naming
Thomas Junk <thomas.junk@intevation.de>
parents:
284
diff
changeset
|
49 const isSysadmin = store.getters["user/isSysAdmin"]; |
284
96860b2bbc0d
fix: User management only for sysadmin
Thomas Junk <thomas.junk@intevation.de>
parents:
278
diff
changeset
|
50 if (!isSysadmin) { |
278
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
51 next("/"); |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
52 } else { |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
53 next(); |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
54 } |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
55 } |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
56 }, |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
57 { |
713
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
58 path: "/logs", |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
59 name: "logs", |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
60 component: Logs, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
61 meta: { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
62 requiresAuth: true |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
63 }, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
64 beforeEnter: (to, from, next) => { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
65 const isSysadmin = store.getters["user/isSysAdmin"]; |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
66 if (!isSysadmin) { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
67 next("/"); |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
68 } else { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
69 next(); |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
70 } |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
71 } |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
72 }, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
73 { |
853 | 74 path: "/systemconfiguration", |
75 name: "systemconfiguration", | |
76 component: Systemconfiguration, | |
77 meta: { | |
78 requiresAuth: true | |
79 }, | |
80 beforeEnter: (to, from, next) => { | |
81 const isSysadmin = store.getters["user/isSysAdmin"]; | |
82 if (!isSysadmin) { | |
83 next("/"); | |
84 } else { | |
85 next(); | |
86 } | |
87 } | |
88 }, | |
89 { | |
1173 | 90 path: "/importqueue", |
91 name: "importqueue", | |
92 component: Importqueue, | |
93 meta: { | |
94 requiresAuth: true | |
95 }, | |
96 beforeEnter: (to, from, next) => { | |
97 const isWaterwayAdmin = store.getters["user/isSysAdmin"]; | |
98 if (!isWaterwayAdmin) { | |
1142
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
99 next("/"); |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
100 } else { |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
101 next(); |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
102 } |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
103 } |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
104 }, |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
105 { |
6 | 106 path: "/", |
30 | 107 name: "mainview", |
6 | 108 component: Main, |
3 | 109 meta: { |
110 requiresAuth: true | |
160
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
111 }, |
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
112 beforeEnter: (to, from, next) => { |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
113 const expiresFromPastSession = toMillisFromString( |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
114 localStorage.getItem("expires") |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
115 ); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
116 if (sessionStillActive(expiresFromPastSession)) { |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
117 store.commit("user/setUser", localStorage.getItem("user")); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
118 store.commit("user/setExpires", expiresFromPastSession); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
119 store.commit("user/setRoles", localStorage.getItem("roles")); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
120 store.commit("user/setIsAuthenticate", true); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
121 } else { |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
122 store.commit("user/clearAuth"); |
160
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
123 } |
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
124 next(); |
3 | 125 } |
126 }, | |
127 { | |
128 path: "*", | |
129 component: Login | |
130 } | |
131 ] | |
132 }); | |
133 | |
134 router.beforeEach((to, from, next) => { | |
135 const requiresAuth = to.matched.some(record => record.meta.requiresAuth); | |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
136 const loggedIn = store.state.user.isAuthenticated; |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
137 const expiresFromPastSession = toMillisFromString( |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
138 localStorage.getItem("expires") |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
139 ); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
140 const authRequired = |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
141 requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession)); |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
142 if (authRequired) { |
6 | 143 next("/login"); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
144 } else if (!authRequired) { |
3 | 145 next(); |
146 } else { | |
147 next(); | |
148 } | |
149 }); | |
150 | |
151 export default router; |