Mercurial > gemma
annotate client/src/lib/session.js @ 4180:91cb4a7b1b13
Always try to translate to readable error if import failed
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 05 Aug 2019 18:21:19 +0200 |
parents | 8775bea8042a |
children | f0be2aec953a |
rev | line source |
---|---|
1362
ca33ad696594
remove the first empyty lines
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1361
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
2 * without warranty, see README.md and license for details. |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1272
diff
changeset
|
3 * |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1272
diff
changeset
|
6 * |
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1272
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
9 * Software engineering by Intevation GmbH |
1361
ea3a89a1813a
remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents:
1272
diff
changeset
|
10 * |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
11 * Author(s): |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
12 * Thomas Junk <thomas.junk@intevation.de> |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
13 */ |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
14 |
1701
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
15 import app from "@/main"; |
3685
8775bea8042a
client: layers: unset layer config on logout
Markus Kottlaender <markus@intevation.de>
parents:
1701
diff
changeset
|
16 import { unsetLayerConfigs } from "@/components/map/layers"; |
1701
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
17 |
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
18 const logOff = () => { |
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
19 app.$snotify.clear(); |
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
20 app.$store.commit("reset"); |
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
21 app.$store.commit("user/clearAuth"); |
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
22 app.$router.push("/login"); |
3685
8775bea8042a
client: layers: unset layer config on logout
Markus Kottlaender <markus@intevation.de>
parents:
1701
diff
changeset
|
23 unsetLayerConfigs(); |
1701
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
24 }; |
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
25 |
1272
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
26 /** |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
27 * Compares whether session is current |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
28 * based on the expiry information and the |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
29 * current date |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
30 * |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
31 * @param {number} expiresFromPastSession |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
32 */ |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
33 function sessionStillActive(expiresFromPastSession) { |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
34 if (!expiresFromPastSession) return false; |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
35 const now = Date.now(); |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
36 const stillActive = now < expiresFromPastSession; |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
37 return stillActive; |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
38 } |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
39 /** |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
40 * Converts a given unix time to Milliseconds |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
41 * |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
42 * @param {string} timestring |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
43 */ |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
44 function toMillisFromString(timestring) { |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
45 return timestring * 1000; |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
46 } |
bc55ffaeb639
cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
47 |
1701
f4bd67daaaff
feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents:
1362
diff
changeset
|
48 export { logOff, sessionStillActive, toMillisFromString }; |