annotate client/src/store/user.js @ 1363:d0c4d17ee7ab

add missing authors * add missing authors to license headers after checking in /client/src/
author Fadi Abbud <fadi.abbud@intevation.de>
date Mon, 26 Nov 2018 12:18:55 +0100
parents ca33ad696594
children 2ea2a14f7b25
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
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
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: 1296
diff changeset
3 *
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
diff changeset
4 * SPDX-License-Identifier: AGPL-3.0-or-later
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
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: 1296
diff changeset
6 *
ea3a89a1813a remove trailing whitespace, add headers for Makefile, add the missed authors
Fadi Abbud <fadi.abbud@intevation.de>
parents: 1296
diff changeset
7 * Copyright (C) 2018 by via donau
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
diff changeset
8 * – Österreichische Wasserstraßen-Gesellschaft mbH
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
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: 1296
diff changeset
10 *
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
diff changeset
11 * Author(s):
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
diff changeset
12 * Thomas Junk <thomas.junk@intevation.de>
1363
d0c4d17ee7ab add missing authors
Fadi Abbud <fadi.abbud@intevation.de>
parents: 1362
diff changeset
13 * Markus Kottländer <markus@intevation.de>
1019
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
diff changeset
14 */
ca628dce90dd Licensing information added
Thomas Junk <thomas.junk@intevation.de>
parents: 585
diff changeset
15
1272
bc55ffaeb639 cleaned up client/src directory
Markus Kottlaender <markus@intevation.de>
parents: 1122
diff changeset
16 import { HTTP } from "../lib/http";
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
17
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
18 const init = () => {
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
19 return {
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
20 isAuthenticated: false,
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
21 expires: null,
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
22 roles: [],
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
23 user: ""
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
24 };
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
25 };
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
26
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
27 export default {
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
28 init,
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
29 namespaced: true,
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
30 state: init(),
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
31 getters: {
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
32 isWaterwayAdmin: state => {
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
33 return state.roles.includes("waterway_admin");
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
34 },
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
35 isSysAdmin: state => {
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
36 return state.roles.includes("sys_admin");
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
37 }
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
38 },
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 mutations: {
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
40 authSuccess: (state, data) => {
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
41 const { token, user, expires, roles } = data;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
42 localStorage.setItem("expires", expires);
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
43 localStorage.setItem("roles", roles);
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
44 localStorage.setItem("token", token);
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
45 localStorage.setItem("user", user);
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
46 state.expires = expires;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
47 state.roles = roles;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
48 state.user = user;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
49 state.authenticated = true;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
50 },
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
51 clearAuth: () => {
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
52 localStorage.removeItem("expires");
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
53 localStorage.removeItem("roles");
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
54 localStorage.removeItem("token");
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
55 localStorage.removeItem("user");
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
56 },
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
57 setUser: (state, name) => {
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
58 state.user = name;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
59 },
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
60 setRoles: (state, roles) => {
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
61 state.roles = roles;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
62 },
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
63 setExpires: (state, expires) => {
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
64 state.expires = expires;
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
65 },
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
66 setIsAuthenticate: state => {
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
67 state.isAuthenticated = true;
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
68 }
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
69 },
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
70 actions: {
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
71 login({ commit }, user) {
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
72 // using POST is a bit more secure than GET
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
73 return new Promise((resolve, reject) => {
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
74 HTTP.post("/login", user)
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
75 .then(response => {
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
76 commit("authSuccess", response.data);
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
77 resolve(response);
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
78 })
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
79 .catch(error => {
1296
99c039e86624 replaced manual store cleanup on logout with central store reset
Markus Kottlaender <markus@intevation.de>
parents: 1272
diff changeset
80 commit("reset", null, { root: true });
1122
a4c74a95c177 minor store refactoring
Markus Kottlaender <markus@intevation.de>
parents: 1114
diff changeset
81 commit("clearAuth");
585
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
82 reject(error);
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
83 });
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
84 });
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
85 }
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
86 }
ef307bd6b5d8 refac: restructured client application
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
87 };