Mercurial > gemma
annotate client/src/router.js @ 1443:6b100f639178
removed blue borders from fairwayprofile and infobar
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Fri, 30 Nov 2018 13:20:26 +0100 |
parents | f4b3fb43b311 |
children | 0ded4c56978e |
rev | line source |
---|---|
1362
ca33ad696594
remove the first empyty lines
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1296
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
2 * 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
|
3 * |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
5 * 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
|
6 * |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
9 * Software engineering by Intevation GmbH |
1142
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
10 * |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
11 * Author(s): |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
12 * Thomas Junk <thomas.junk@intevation.de> |
1363 | 13 * Bernhard Reiter <bernhard@intevation.de> |
14 * Markus Kottländer <markus@intevation.de> | |
1019
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
15 */ |
3 | 16 import Vue from "vue"; |
17 import Router from "vue-router"; | |
18 import store from "./store"; | |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1244
diff
changeset
|
19 import { sessionStillActive, toMillisFromString } from "./lib/session"; |
3 | 20 |
483
27502291e564
docs: Added comments on non trivial parts of the code
Thomas Junk <thomas.junk@intevation.de>
parents:
466
diff
changeset
|
21 /* facilitate codesplitting */ |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1244
diff
changeset
|
22 const Login = () => import("./components/Login.vue"); |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1244
diff
changeset
|
23 const Main = () => import("./components/map/Main.vue"); |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1244
diff
changeset
|
24 const Usermanagement = () => |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
1244
diff
changeset
|
25 import("./components/admin/usermanagement/Usermanagement.vue"); |
1276
aec9ed491dad
more cleanup in client/src
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
26 const Logs = () => import("./components/admin/Logs.vue"); |
aec9ed491dad
more cleanup in client/src
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
27 const Importqueue = () => import("./components/admin/Importqueue.vue"); |
1429
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
28 const Importschedule = () => |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
29 import("./components/admin/importschedule/Importschedule.vue"); |
853 | 30 const Systemconfiguration = () => |
1276
aec9ed491dad
more cleanup in client/src
Markus Kottlaender <markus@intevation.de>
parents:
1272
diff
changeset
|
31 import("./components/admin/Systemconfiguration.vue"); |
466
e3035621cc52
refac: Small improvement of loading time with code splitting
Thomas Junk <thomas.junk@intevation.de>
parents:
285
diff
changeset
|
32 |
3 | 33 Vue.use(Router); |
34 | |
35 const router = new Router({ | |
36 routes: [ | |
37 { | |
6 | 38 path: "/login", |
3 | 39 name: "login", |
40 component: Login | |
41 }, | |
42 { | |
581 | 43 path: "/usermanagement", |
44 name: "usermanagement", | |
45 component: Usermanagement, | |
278
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
46 meta: { |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
47 requiresAuth: true |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
48 }, |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
49 beforeEnter: (to, from, next) => { |
285
8e22d1f16f81
refactor: better variable naming
Thomas Junk <thomas.junk@intevation.de>
parents:
284
diff
changeset
|
50 const isSysadmin = store.getters["user/isSysAdmin"]; |
284
96860b2bbc0d
fix: User management only for sysadmin
Thomas Junk <thomas.junk@intevation.de>
parents:
278
diff
changeset
|
51 if (!isSysadmin) { |
278
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
52 next("/"); |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
53 } else { |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
54 next(); |
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 }, |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
58 { |
713
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
59 path: "/logs", |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
60 name: "logs", |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
61 component: Logs, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
62 meta: { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
63 requiresAuth: true |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
64 }, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
65 beforeEnter: (to, from, next) => { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
66 const isSysadmin = store.getters["user/isSysAdmin"]; |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
67 if (!isSysadmin) { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
68 next("/"); |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
69 } else { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
70 next(); |
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 }, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
74 { |
853 | 75 path: "/systemconfiguration", |
76 name: "systemconfiguration", | |
77 component: Systemconfiguration, | |
78 meta: { | |
79 requiresAuth: true | |
80 }, | |
81 beforeEnter: (to, from, next) => { | |
82 const isSysadmin = store.getters["user/isSysAdmin"]; | |
83 if (!isSysadmin) { | |
84 next("/"); | |
85 } else { | |
86 next(); | |
87 } | |
88 } | |
89 }, | |
90 { | |
1173 | 91 path: "/importqueue", |
92 name: "importqueue", | |
93 component: Importqueue, | |
94 meta: { | |
95 requiresAuth: true | |
96 }, | |
97 beforeEnter: (to, from, next) => { | |
1429
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
98 const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"]; |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
99 if (!isWaterwayAdmin) { |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
100 next("/"); |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
101 } else { |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
102 next(); |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
103 } |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
104 } |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
105 }, |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
106 { |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
107 path: "/importschedule", |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
108 name: "importschedule", |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
109 component: Importschedule, |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
110 meta: { |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
111 requiresAuth: true |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
112 }, |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
113 beforeEnter: (to, from, next) => { |
f4b3fb43b311
automatic imports WIP added
Thomas Junk <thomas.junk@intevation.de>
parents:
1363
diff
changeset
|
114 const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"]; |
1173 | 115 if (!isWaterwayAdmin) { |
1142
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
116 next("/"); |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
117 } else { |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
118 next(); |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
119 } |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
120 } |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
121 }, |
dc3f0277628a
feat: Importqueue listing (Proof of concept)
Thomas Junk <thomas.junk@intevation.de>
parents:
1122
diff
changeset
|
122 { |
6 | 123 path: "/", |
30 | 124 name: "mainview", |
6 | 125 component: Main, |
3 | 126 meta: { |
127 requiresAuth: true | |
160
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
128 }, |
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
129 beforeEnter: (to, from, next) => { |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
130 const expiresFromPastSession = toMillisFromString( |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
131 localStorage.getItem("expires") |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
132 ); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
133 if (sessionStillActive(expiresFromPastSession)) { |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
134 store.commit("user/setUser", localStorage.getItem("user")); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
135 store.commit("user/setExpires", expiresFromPastSession); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
136 store.commit("user/setRoles", localStorage.getItem("roles")); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
137 store.commit("user/setIsAuthenticate", true); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
138 } else { |
1296
99c039e86624
replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents:
1276
diff
changeset
|
139 store.commit("reset"); |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
140 store.commit("user/clearAuth"); |
160
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
141 } |
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
142 next(); |
3 | 143 } |
144 }, | |
145 { | |
146 path: "*", | |
147 component: Login | |
148 } | |
149 ] | |
150 }); | |
151 | |
152 router.beforeEach((to, from, next) => { | |
153 const requiresAuth = to.matched.some(record => record.meta.requiresAuth); | |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
154 const loggedIn = store.state.user.isAuthenticated; |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
155 const expiresFromPastSession = toMillisFromString( |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
156 localStorage.getItem("expires") |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
157 ); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
158 const authRequired = |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
159 requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession)); |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
160 if (authRequired) { |
6 | 161 next("/login"); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
162 } else if (!authRequired) { |
3 | 163 next(); |
164 } else { | |
165 next(); | |
166 } | |
167 }); | |
168 | |
169 export default router; |