Skip to content
Snippets Groups Projects
Commit 1024ff05 authored by Sébastien DA ROCHA's avatar Sébastien DA ROCHA :bicyclist:
Browse files

Merge branch 'ticket/11714' into 'develop'

add error in user store

See merge request !13
parents c9b6bcc3 0749df73
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,7 @@ export default new Vuex.Store({ ...@@ -30,6 +30,7 @@ export default new Vuex.Store({
map map
}, },
state: { state: {
error: null,
logged: false, logged: false,
user: false, user: false,
configuration:null, configuration:null,
...@@ -43,6 +44,9 @@ export default new Vuex.Store({ ...@@ -43,6 +44,9 @@ export default new Vuex.Store({
}, },
mutations: { mutations: {
error(state, data) {
return state.error = data
},
SET_PROJECTS(state, projects) { SET_PROJECTS(state, projects) {
state.projects = projects; state.projects = projects;
}, },
...@@ -125,15 +129,23 @@ export default new Vuex.Store({ ...@@ -125,15 +129,23 @@ export default new Vuex.Store({
password: payload.password, password: payload.password,
}) })
.then((response) => { .then((response) => {
commit('error', null)
if (response && response.status === 200) { if (response && response.status === 200) {
// * use stored previous route to go back after login if page not open on login at first // * use stored previous route to go back after login if page not open on login at first
const routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/" let routerHistory = ''
if (router.options.routerHistory[0] != undefined){
routerHistory = router.options.routerHistory[0].name !== "login" ? router.options.routerHistory : "/"
} else {
routerHistory = "/"
}
commit("SET_USER", response.data.user); commit("SET_USER", response.data.user);
router.push(routerHistory[routerHistory.length - 1] || "/") router.push(routerHistory[routerHistory.length - 1] || "/")
dispatch("GET_USER_LEVEL_PROJECTS"); dispatch("GET_USER_LEVEL_PROJECTS");
} }
}) })
.catch(() => { .catch((error) => {
if (error.response.status === 403)
commit('error', error.response.data.detail)
commit("SET_USER", false); commit("SET_USER", false);
}); });
} }
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
<script> <script>
import { mapState } from "vuex";
export default { export default {
name: "Login", name: "Login",
...@@ -76,6 +77,7 @@ export default { ...@@ -76,6 +77,7 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(["error"]),
LOGO_PATH:function () { LOGO_PATH:function () {
return this.$store.state.configuration.VUE_APP_LOGO_PATH; return this.$store.state.configuration.VUE_APP_LOGO_PATH;
}, },
...@@ -87,11 +89,19 @@ export default { ...@@ -87,11 +89,19 @@ export default {
}, },
}, },
methods: { methods: {
login() { async login() {
this.$store.dispatch("LOGIN", { this.$store.dispatch("LOGIN", {
username: this.username_value, username: this.username_value,
password: this.password_value, password: this.password_value,
}); })
.then(() => {
if (this.error != null){
this.form.errors = "Les informations d'identification sont incorrectes.";
}
})
.catch(() => {
this.form.errors = this.error
});
}, },
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment