|
@@ -14,7 +14,9 @@ export default {
|
|
|
logout_token: null,
|
|
|
isloggedin: false,
|
|
|
isAdmin: false,
|
|
|
- canSearch: false
|
|
|
+ isAdherent: false,
|
|
|
+ canSearch: false,
|
|
|
+ roles: []
|
|
|
},
|
|
|
|
|
|
// getters
|
|
@@ -53,6 +55,7 @@ export default {
|
|
|
if(state.roles.indexOf('adherent') != -1){
|
|
|
// console.log('is admin');
|
|
|
state.canSearch = true
|
|
|
+ state.isAdherent = true
|
|
|
}
|
|
|
},
|
|
|
setLoggedOut (state) {
|
|
@@ -73,16 +76,32 @@ export default {
|
|
|
|
|
|
// actions
|
|
|
actions : {
|
|
|
+ userRegister({ dispatch, commit, state }, credentials){
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ REST.post('/user/register?_format=json', credentials)
|
|
|
+ .then(({ data }) => {
|
|
|
+ console.log('user REST registered', data);
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
+ .catch(( error ) => {
|
|
|
+ console.warn('Issue with register', error)
|
|
|
+ Promise.reject(error)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
userLogin({ dispatch, commit, state }, credentials){
|
|
|
- dispatch('getToken', credentials)
|
|
|
- .then(() => {
|
|
|
- dispatch('getUser').then((userdata) => {
|
|
|
- console.log('User Loggedin');
|
|
|
- if (state.isAdmin){
|
|
|
- window.location.reload(true);
|
|
|
- }
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ dispatch('getToken', credentials)
|
|
|
+ .then(() => {
|
|
|
+ dispatch('getUser').then((userdata) => {
|
|
|
+ console.log('User Loggedin');
|
|
|
+ if (state.isAdmin){
|
|
|
+ window.location.reload(true);
|
|
|
+ }
|
|
|
+ resolve()
|
|
|
+ })
|
|
|
})
|
|
|
- })
|
|
|
+ })
|
|
|
},
|
|
|
getToken ({ dispatch, commit, state }, credentials) {
|
|
|
return REST.post('/user/login?_format=json', credentials)
|