annotate client/src/stores/user.js @ 13:88d0d60924cf

Move vuejs app into subdir `client` Using a subdirectory for the web application keeps more structure in the repo.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 20 Jun 2018 17:02:06 +0200
parents src/stores/user.js@7c1bde663c8e
children 992e17912405
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
1 import { HTTP } from "../lib/http";
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
2
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
3 const User = {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
4 namespaced: true,
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
5 state: {
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
6 authenticated: false
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
7 },
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
8 getters: {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
9 authenticated: state => {
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
10 return state.authenticated;
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
11 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
12 },
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
13 mutations: {
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
14 auth_success: (state, token) => {
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
15 state.authenticated = true;
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
16 sessionStorage.setItem("token", token);
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
17 },
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
18 auth_failure: state => {
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
19 state.authenticated = false;
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
20 sessionStorage.removeItem("token");
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
21 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
22 },
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
23 actions: {
6
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
24 login({ commit }, user) {
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
25 return new Promise((resolve, reject) => {
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
26 HTTP.post("/token", user)
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
27 .then(response => {
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
28 let token = response.data;
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
29 commit("auth_success", token);
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
30 resolve(response);
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
31 })
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
32 .catch(error => {
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
33 commit("auth_failure");
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
34 reject(error);
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
35 });
7c1bde663c8e current frontend
Thomas Junk <thomas.junk@intevation.de>
parents: 3
diff changeset
36 });
3
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
37 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
38 }
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 };
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
40
1597506a2241 merge with vue-cli
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
41 export default User;