Skip to content
Snippets Groups Projects

REDMINE_ISSUE-17472 | Connexion annuaire MRN WP et GéoContrib

Merged Timothee P requested to merge redmine-issues/17473 into develop
+ 29
2
@@ -54,7 +54,7 @@ export default new Vuex.Store({
SET_CONFIG(state, payload) {
state.configuration = payload;
},
SET_COOKIE(state, cookie) {
SET_COOKIE(state, cookie) { // ! not called anywhere. Delete it ?
state.cookie = cookie;
},
SET_STATIC_PAGES(state, staticPages) {
@@ -175,7 +175,7 @@ export default new Vuex.Store({
}
},
USER_INFO({ state, commit }) {
USER_INFO({ state, commit, dispatch }) {
if (!state.user) {
axios
.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}user_info/`)
@@ -187,6 +187,7 @@ export default new Vuex.Store({
})
.catch(() => {
//* if an url to redirect to an external authentification system is present, do not redirect to the login page
const token = new URLSearchParams(window.location.search).get('token');
if (!state.configuration.VUE_APP_LOGIN_URL) {
const url = window.location.href;
if (url.includes('projet-partage')) {
@@ -195,11 +196,37 @@ export default new Vuex.Store({
} else {
router.push({ name: 'login' });
}
} else if (token) {
dispatch('CONNECT_SSO_WITH_TOKEN', token);
}
});
}
},
async CONNECT_SSO_WITH_TOKEN({ commit, dispatch }, token) {
axios
.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}login-token/?token=${token}`)
.then((response) => {
if (response && (response.status === 200 || response.status === 201)) {
const user = response.data;
commit('SET_USER', user);
dispatch('GET_USER_LEVEL_PROJECTS');
dispatch('GET_USER_LEVEL_PERMISSIONS');
commit('DISPLAY_MESSAGE', {
comment: `Vous êtes maintenant connecté ${ user.first_name} ${ user.last_name}`, level: 'positive'
});
}
})
.catch((err) => {
console.error(err);
console.log(err.toString());
console.log(err.message);
commit('DISPLAY_MESSAGE', {
comment: 'La connexion a échoué.', level: 'negative'
});
});
},
async GET_USER_TOKEN({ commit }) {
const response = await axios.get(`${this.state.configuration.VUE_APP_DJANGO_API_BASE}get-token`);
if (
Loading