|
@@ -12,7 +12,8 @@ export default {
|
|
|
mail:'',
|
|
|
token: null,
|
|
|
logout_token: null,
|
|
|
- isloggedin: false
|
|
|
+ isloggedin: false,
|
|
|
+ isAdmin: false
|
|
|
},
|
|
|
|
|
|
// getters
|
|
@@ -36,11 +37,22 @@ export default {
|
|
|
state.mail = data.mail[0].value
|
|
|
state.uuid = data.uuid[0].value
|
|
|
},
|
|
|
+ setRoles (state, roles) {
|
|
|
+ state.roles = []
|
|
|
+ for (var i = 0; i < roles.length; i++) {
|
|
|
+ state.roles.push(roles[i].target_id)
|
|
|
+ }
|
|
|
+ if(state.roles.indexOf('admin') != -1){
|
|
|
+ console.log('is admin');
|
|
|
+ state.isAdmin = true
|
|
|
+ }
|
|
|
+ },
|
|
|
setLoggedOut (state) {
|
|
|
state.uid= null
|
|
|
state.mail = ''
|
|
|
state.token = null
|
|
|
state.isloggedin = false
|
|
|
+ state.asAdmin = false
|
|
|
state.logout_token = null
|
|
|
}
|
|
|
},
|
|
@@ -59,29 +71,41 @@ export default {
|
|
|
Promise.reject(error)
|
|
|
})
|
|
|
},
|
|
|
- getUser ({ commit, state }) {
|
|
|
+ getUser ({ dispatch, commit, state }) {
|
|
|
let params = {
|
|
|
token: state.token
|
|
|
}
|
|
|
REST.get(`/user/${state.uid}?_format=json`, params)
|
|
|
.then(({ data }) => {
|
|
|
console.log('user REST getUser data', data)
|
|
|
- console.log('roles', data['roles']);
|
|
|
+ console.log('roles', data['roles'])
|
|
|
commit('setUser', data)
|
|
|
- JSONAPI.get(`/user/user/${state.uuid}?include=roles`)
|
|
|
- .then(({ data }) => {
|
|
|
- console.log('user JSONAPI getUser data', data)
|
|
|
- })
|
|
|
- .catch(( error ) => {
|
|
|
- console.warn('Issue with getUser', error)
|
|
|
- Promise.reject(error)
|
|
|
- })
|
|
|
+ if(data.roles){
|
|
|
+ commit('setRoles', data.roles)
|
|
|
+ // dispatch('checkLoginRole')
|
|
|
+ }
|
|
|
+ // dispatch('checkLoginRole')
|
|
|
+ // JSONAPI.get(`/user/user/${state.uuid}?include=roles`)
|
|
|
+ // .then(({ data }) => {
|
|
|
+ // console.log('user JSONAPI getUser data', data)
|
|
|
+ // })
|
|
|
+ // .catch(( error ) => {
|
|
|
+ // console.warn('Issue with getUser', error)
|
|
|
+ // Promise.reject(error)
|
|
|
+ // })
|
|
|
})
|
|
|
.catch(( error ) => {
|
|
|
console.warn('Issue with getUser', error)
|
|
|
Promise.reject(error)
|
|
|
})
|
|
|
},
|
|
|
+ // checkLoginRole ({ commit, state }){
|
|
|
+ // console.log('checkLoginRole', state.roles, state.roles.indexOf('admin'))
|
|
|
+ // if(state.roles.indexOf('admin') != -1){
|
|
|
+ // console.log('is admin')
|
|
|
+ // window.
|
|
|
+ // }
|
|
|
+ // },
|
|
|
userLogout ({ commit, state }) {
|
|
|
let credentials = qs.stringify({
|
|
|
token: state.token
|