Mercurial > gemma
view client/src/stores/user.js @ 485:7a8644e9e50e
client: add (unwired) password reset form
* Add password reset form to the Login view. Pressing the forgotton
link will blend it in and currently the send button will hide it again.
This is a good first place because an additional view and route would be
more work with the same functionality. It doe not yet trigger action
with the backend.
* Put password forgotten part and bottom logo in divs beside the first form
which matches the semantics better.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Fri, 24 Aug 2018 12:14:56 +0200 |
parents | 2ac37419f593 |
children | 04a6bea229e4 |
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) => { // axios will add the application/x-www-form-urlencoded header this way HTTP.post("/login", user) .then(response => { commit("auth_success", response.data); resolve(response); }) .catch(error => { commit("clear_auth"); reject(error); }); }); } } }; export default User;