annotate client/src/lib/session.js @ 5095:e21cbb9768a2

Prevent duplicate fairway areas In principal, there can be only one or no fairway area at each point on the map. Since polygons from real data will often be topologically inexact, just disallow equal geometries. This will also help to avoid importing duplicates with concurrent imports, once the history of fairway dimensions will be preserved.
author Tom Gottfried <tom@intevation.de>
date Wed, 25 Mar 2020 18:10:02 +0100
parents 96a544504818
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5076
96a544504818 move layer.js and styles.js to layers directory
Thomas Junk <thomas.junk@intevation.de>
parents: 4415
diff changeset
15 import { HTTP } from "@/lib/http";
1701
f4bd67daaaff feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents: 1362
diff changeset
16 import app from "@/main";
4379
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
17 import { displayError } from "@/lib/errors";
5076
96a544504818 move layer.js and styles.js to layers directory
Thomas Junk <thomas.junk@intevation.de>
parents: 4415
diff changeset
18 import { unsetLayerConfigs } from "@/components/layers/layers";
1701
f4bd67daaaff feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents: 1362
diff changeset
19
f4bd67daaaff feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents: 1362
diff changeset
20 const logOff = () => {
4415
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
21 const hasToken = localStorage.getItem("token");
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
22 if (!hasToken) return;
4379
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
23 HTTP.get("/logout", {
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
24 headers: {
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
25 "X-Gemma-Auth": localStorage.getItem("token"),
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
26 "Content-type": "text/xml; charset=UTF-8"
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
27 }
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
28 })
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
29 .catch(error => {
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
30 const { status, data } = error.response;
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
31 displayError({
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
32 title: this.$gettext("Backend Error"),
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
33 message: `${status}: ${data.message || data}`
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
34 });
4415
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
35 })
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
36 .finally(() => {
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
37 app.$snotify.clear();
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
38 app.$store.commit("reset");
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
39 app.$store.commit("user/clearAuth");
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
40 app.$router.push("/login");
8dde014af77b session: Remove potential infinite loop of logging out.
Thomas Junk <thomas.junk@intevation.de>
parents: 4379
diff changeset
41 unsetLayerConfigs();
4379
f0be2aec953a logout: Logging out triggers a request to log the user out on server side
Thomas Junk <thomas.junk@intevation.de>
parents: 3685
diff changeset
42 });
1701
f4bd67daaaff feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents: 1362
diff changeset
43 };
f4bd67daaaff feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents: 1362
diff changeset
44
1272
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
45 /**
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
46 * Compares whether session is current
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
47 * based on the expiry information and the
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
48 * current date
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
49 *
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
50 * @param {number} expiresFromPastSession
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
51 */
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
52 function sessionStillActive(expiresFromPastSession) {
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
53 if (!expiresFromPastSession) return false;
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
54 const now = Date.now();
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
55 const stillActive = now < expiresFromPastSession;
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
56 return stillActive;
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
57 }
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
58 /**
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
59 * Converts a given unix time to Milliseconds
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
60 *
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
61 * @param {string} timestring
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
62 */
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
63 function toMillisFromString(timestring) {
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
64 return timestring * 1000;
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
65 }
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents:
diff changeset
66
1701
f4bd67daaaff feat: force login on invalid session
Thomas Junk <thomas.junk@intevation.de>
parents: 1362
diff changeset
67 export { logOff, sessionStillActive, toMillisFromString };