Mercurial > gemma
annotate client/src/router.js @ 1123:d9e6a1f6f394 store-refactoring
moved all collapse flags for UI elements to store
UI elements can now be expanded/collapsed via the application store
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Tue, 06 Nov 2018 13:00:17 +0100 |
parents | a4c74a95c177 |
children | dc3f0277628a |
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. |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
4 * |
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 |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
7 * |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
8 * Copyright (C) 2018 by via donau |
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 |
ca628dce90dd
Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents:
853
diff
changeset
|
11 * |
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"); |
853 | 28 const Systemconfiguration = () => |
29 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
|
30 |
3 | 31 Vue.use(Router); |
32 | |
33 const router = new Router({ | |
34 routes: [ | |
35 { | |
6 | 36 path: "/login", |
3 | 37 name: "login", |
38 component: Login | |
39 }, | |
40 { | |
581 | 41 path: "/usermanagement", |
42 name: "usermanagement", | |
43 component: Usermanagement, | |
278
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
44 meta: { |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
45 requiresAuth: true |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
46 }, |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
47 beforeEnter: (to, from, next) => { |
285
8e22d1f16f81
refactor: better variable naming
Thomas Junk <thomas.junk@intevation.de>
parents:
284
diff
changeset
|
48 const isSysadmin = store.getters["user/isSysAdmin"]; |
284
96860b2bbc0d
fix: User management only for sysadmin
Thomas Junk <thomas.junk@intevation.de>
parents:
278
diff
changeset
|
49 if (!isSysadmin) { |
278
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
50 next("/"); |
9c1dfadb53aa
feat: usermanagement - route established and secured
Thomas Junk <thomas.junk@intevation.de>
parents:
165
diff
changeset
|
51 } else { |
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 } |
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 { |
713
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
57 path: "/logs", |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
58 name: "logs", |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
59 component: Logs, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
60 meta: { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
61 requiresAuth: true |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
62 }, |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
63 beforeEnter: (to, from, next) => { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
64 const isSysadmin = store.getters["user/isSysAdmin"]; |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
65 if (!isSysadmin) { |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
66 next("/"); |
badbc0207418
feat: systeminformation feature added
Thomas Junk <thomas.junk@intevation.de>
parents:
592
diff
changeset
|
67 } else { |
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 } |
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 { |
853 | 73 path: "/systemconfiguration", |
74 name: "systemconfiguration", | |
75 component: Systemconfiguration, | |
76 meta: { | |
77 requiresAuth: true | |
78 }, | |
79 beforeEnter: (to, from, next) => { | |
80 const isSysadmin = store.getters["user/isSysAdmin"]; | |
81 if (!isSysadmin) { | |
82 next("/"); | |
83 } else { | |
84 next(); | |
85 } | |
86 } | |
87 }, | |
88 { | |
6 | 89 path: "/", |
30 | 90 name: "mainview", |
6 | 91 component: Main, |
3 | 92 meta: { |
93 requiresAuth: true | |
160
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
94 }, |
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
95 beforeEnter: (to, from, next) => { |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
96 const expiresFromPastSession = toMillisFromString( |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
97 localStorage.getItem("expires") |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
98 ); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
99 if (sessionStillActive(expiresFromPastSession)) { |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
100 store.commit("user/setUser", localStorage.getItem("user")); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
101 store.commit("user/setExpires", expiresFromPastSession); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
102 store.commit("user/setRoles", localStorage.getItem("roles")); |
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
103 store.commit("user/setIsAuthenticate", true); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
104 } else { |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
105 store.commit("user/clearAuth"); |
160
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
106 } |
061209505028
feat: Login and logout with session restoration implemented
Thomas Junk <thomas.junk@intevation.de>
parents:
30
diff
changeset
|
107 next(); |
3 | 108 } |
109 }, | |
110 { | |
111 path: "*", | |
112 component: Login | |
113 } | |
114 ] | |
115 }); | |
116 | |
117 router.beforeEach((to, from, next) => { | |
118 const requiresAuth = to.matched.some(record => record.meta.requiresAuth); | |
1122
a4c74a95c177
minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents:
1019
diff
changeset
|
119 const loggedIn = store.state.user.isAuthenticated; |
165
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
120 const expiresFromPastSession = toMillisFromString( |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
121 localStorage.getItem("expires") |
4bf2173748f3
refactor: extracted the string to milisecondconversion
Thomas Junk <thomas.junk@intevation.de>
parents:
162
diff
changeset
|
122 ); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
123 const authRequired = |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
124 requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession)); |
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
125 if (authRequired) { |
6 | 126 next("/login"); |
162
9908260d1e6a
Refactor: Login expiry refactored to lib
Thomas Junk <thomas.junk@intevation.de>
parents:
160
diff
changeset
|
127 } else if (!authRequired) { |
3 | 128 next(); |
129 } else { | |
130 next(); | |
131 } | |
132 }); | |
133 | |
134 export default router; |