|
@@ -41,6 +41,9 @@ export default {
|
|
console.log('SetCsrftoken', token)
|
|
console.log('SetCsrftoken', token)
|
|
state.csrf_token = token
|
|
state.csrf_token = token
|
|
},
|
|
},
|
|
|
|
+ SetLogouttoken (state, token) {
|
|
|
|
+ state.logout_token = token
|
|
|
|
+ },
|
|
setToken (state, data) {
|
|
setToken (state, data) {
|
|
console.log('setToken', data)
|
|
console.log('setToken', data)
|
|
state.uid = data.current_user.uid
|
|
state.uid = data.current_user.uid
|
|
@@ -183,10 +186,10 @@ export default {
|
|
},
|
|
},
|
|
userLogin ({ dispatch, commit, state }, credentials) {
|
|
userLogin ({ dispatch, commit, state }, credentials) {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
- dispatch('getToken', credentials)
|
|
|
|
|
|
+ dispatch('postUserLogin', credentials)
|
|
// TODO: catch failed login
|
|
// TODO: catch failed login
|
|
.then((response) => {
|
|
.then((response) => {
|
|
- console.log('userLogin dispatch getToken response', response)
|
|
|
|
|
|
+ console.log('userLogin dispatch postUserLogin response', response)
|
|
|
|
|
|
if (response.status === 200) {
|
|
if (response.status === 200) {
|
|
commit('setToken', response.data)
|
|
commit('setToken', response.data)
|
|
@@ -194,7 +197,7 @@ export default {
|
|
console.log('User Loggedin', state.isAdmin, state.isAdherent)
|
|
console.log('User Loggedin', state.isAdmin, state.isAdherent)
|
|
// have to reload systematicly because of autologout library not loaded if not logged in the begining
|
|
// have to reload systematicly because of autologout library not loaded if not logged in the begining
|
|
if (state.isAdmin) {
|
|
if (state.isAdmin) {
|
|
- window.location.reload()
|
|
|
|
|
|
+ // window.location.reload()
|
|
}
|
|
}
|
|
if (state.isAdherent) {
|
|
if (state.isAdherent) {
|
|
// router.push({
|
|
// router.push({
|
|
@@ -202,7 +205,7 @@ export default {
|
|
// })
|
|
// })
|
|
// // TODO: openCloseHamMenu(false)
|
|
// // TODO: openCloseHamMenu(false)
|
|
// dispatch('Common/openCloseHamMenu', false)
|
|
// dispatch('Common/openCloseHamMenu', false)
|
|
- window.location = '/base'
|
|
|
|
|
|
+ // window.location = '/base'
|
|
}
|
|
}
|
|
// else {
|
|
// else {
|
|
// // * window.location.reload()
|
|
// // * window.location.reload()
|
|
@@ -211,18 +214,18 @@ export default {
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
commit('setLoginMessage', response.data.message)
|
|
commit('setLoginMessage', response.data.message)
|
|
- console.warn('Issue with getToken', response)
|
|
|
|
|
|
+ console.warn('Issue with postUserLogin', response)
|
|
console.log('user loggein failed')
|
|
console.log('user loggein failed')
|
|
Promise.reject(new Error('user loggein failed'))
|
|
Promise.reject(new Error('user loggein failed'))
|
|
}
|
|
}
|
|
})
|
|
})
|
|
.catch(error => {
|
|
.catch(error => {
|
|
- console.warn('Issue with Dispatch getToken', error)
|
|
|
|
|
|
+ console.warn('Issue with Dispatch postUserLogin', error)
|
|
Promise.reject(error)
|
|
Promise.reject(error)
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
- getToken ({ dispatch, commit, state }, credentials) {
|
|
|
|
|
|
+ postUserLogin ({ dispatch, commit, state }, credentials) {
|
|
return REST.post('/user/login?_format=json',
|
|
return REST.post('/user/login?_format=json',
|
|
credentials,
|
|
credentials,
|
|
{
|
|
{
|
|
@@ -237,24 +240,34 @@ export default {
|
|
console.log('csrftoken', data)
|
|
console.log('csrftoken', data)
|
|
commit('SetCsrftoken', data)
|
|
commit('SetCsrftoken', data)
|
|
console.log('state.csrf_token', state.csrf_token)
|
|
console.log('state.csrf_token', state.csrf_token)
|
|
- const params = {
|
|
|
|
- token: state.csrf_token
|
|
|
|
- }
|
|
|
|
- REST.get(`/user/${state.uid}?_format=json`, params)
|
|
|
|
|
|
+ // INFO this endpoiunt needs https://www.drupal.org/project/logout_token
|
|
|
|
+ REST.get('/session/logout/token')
|
|
.then(({ data }) => {
|
|
.then(({ data }) => {
|
|
- console.log('user REST getUser data', data)
|
|
|
|
- console.log('roles', data.roles)
|
|
|
|
- // with session_limit, only here we are certain that the user is logged
|
|
|
|
- commit('setUser', data)
|
|
|
|
- if (data.roles) {
|
|
|
|
- commit('setRoles', data.roles)
|
|
|
|
|
|
+ console.log('logout_token', data)
|
|
|
|
+ commit('SetLogouttoken', data)
|
|
|
|
+ const params = {
|
|
|
|
+ token: state.csrf_token
|
|
}
|
|
}
|
|
- // console.log('customer_profiles', data.customer_profiles.length)
|
|
|
|
- // if (data.customer_profiles.length) {
|
|
|
|
- // dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
|
|
|
|
- // }
|
|
|
|
- dispatch('getUserFlagColls')
|
|
|
|
- resolve()
|
|
|
|
|
|
+ REST.get(`/user/${state.uid}?_format=json`, params)
|
|
|
|
+ .then(({ data }) => {
|
|
|
|
+ console.log('user REST getUser data', data)
|
|
|
|
+ console.log('roles', data.roles)
|
|
|
|
+ // with session_limit, only here we are certain that the user is logged
|
|
|
|
+ commit('setUser', data)
|
|
|
|
+ if (data.roles) {
|
|
|
|
+ commit('setRoles', data.roles)
|
|
|
|
+ }
|
|
|
|
+ // console.log('customer_profiles', data.customer_profiles.length)
|
|
|
|
+ // if (data.customer_profiles.length) {
|
|
|
|
+ // dispatch('getUserProfiles', data.customer_profiles[data.customer_profiles.length - 1].target_id)
|
|
|
|
+ // }
|
|
|
|
+ dispatch('getUserFlagColls')
|
|
|
|
+ resolve()
|
|
|
|
+ })
|
|
|
|
+ .catch(error => {
|
|
|
|
+ console.warn('Issue with getUser', error)
|
|
|
|
+ Promise.reject(error)
|
|
|
|
+ })
|
|
})
|
|
})
|
|
.catch(error => {
|
|
.catch(error => {
|
|
console.warn('Issue with getUser', error)
|
|
console.warn('Issue with getUser', error)
|
|
@@ -424,14 +437,20 @@ export default {
|
|
commit('closeFlagColl')
|
|
commit('closeFlagColl')
|
|
},
|
|
},
|
|
userLogout ({ commit, state }) {
|
|
userLogout ({ commit, state }) {
|
|
- const credentials = qs.stringify({
|
|
|
|
- token: state.csrf_token
|
|
|
|
|
|
+ const params = qs.stringify({
|
|
|
|
+ // format: 'json'
|
|
|
|
+ // token: state.logout_token
|
|
})
|
|
})
|
|
- REST.post('/user/logout', credentials)
|
|
|
|
|
|
+ const config = {
|
|
|
|
+ headers: {
|
|
|
|
+ 'X-CSRF-Token': state.csrf_token
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ REST.post('/user/logout?format=json&token=' + state.logout_token, params, config)
|
|
.then(resp => {
|
|
.then(resp => {
|
|
console.log('userLogout resp', resp)
|
|
console.log('userLogout resp', resp)
|
|
- commit('setLoggedOut')
|
|
|
|
- // window.location.reload(true) ???
|
|
|
|
|
|
+ // commit('setLoggedOut')
|
|
|
|
+ // window.location.reload(true)
|
|
})
|
|
})
|
|
.catch(error => {
|
|
.catch(error => {
|
|
console.warn('Issue with logout', error)
|
|
console.warn('Issue with logout', error)
|