Mercurial > gemma
view client/src/application/stores/user.js @ 860:38b682eaa7b1
client: add updateing of bottleneck filter
* Add a watcher on the selectedMorph to trigger the update of the bottleneck
filter.
* Reverse the parameter to updateBottleneckFilter() to the order that was
mostly used.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Fri, 28 Sep 2018 17:19:08 +0200 |
parents | ef307bd6b5d8 |
children | ca628dce90dd |
line wrap: on
line source
import { HTTP } from "../lib/http"; const User = { namespaced: true, state: { authenticated: false, expires: null, roles: [], user: "" }, getters: { isAuthenticated: state => { return state.authenticated; }, userinfo: state => { return state.user; }, roles: state => { return state.roles; }, expires: state => { return state.expires; }, isWaterwayAdmin: state => { return state.roles.includes("waterway_admin"); }, isSysAdmin: state => { return state.roles.includes("sys_admin"); } }, mutations: { auth_success: (state, data) => { const { token, user, expires, roles } = data; localStorage.setItem("expires", expires); localStorage.setItem("roles", roles); localStorage.setItem("token", token); localStorage.setItem("user", user); state.expires = expires; state.roles = roles; state.user = user; state.authenticated = true; }, clear_auth: state => { state.authenticated = false; state.expires = null; state.roles = []; state.user = ""; localStorage.clear(); }, set_user: (state, name) => { state.user = name; }, set_roles: (state, roles) => { state.roles = roles; }, set_expires: (state, expires) => { state.expires = expires; }, set_authenticate: state => { state.authenticated = true; } }, actions: { login({ commit }, user) { // using POST is a bit more secure than GET return new Promise((resolve, reject) => { HTTP.post("/login", user) .then(response => { commit("auth_success", response.data); resolve(response); }) .catch(error => { commit("clear_auth"); reject(error); }); }); } } }; export default User;