From 35e1ac50962cdcf09c32c57eba2024f462ac3381 Mon Sep 17 00:00:00 2001 From: bach Date: Tue, 19 Jan 2021 12:18:28 +0100 Subject: [PATCH] redirect to home page after any logout --- .../custom/materiotheme/assets/dist/main.js | 2 +- .../materiotheme/vuejs/store/modules/user.js | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/web/themes/custom/materiotheme/assets/dist/main.js b/web/themes/custom/materiotheme/assets/dist/main.js index 512068d2..5b714ab4 100644 --- a/web/themes/custom/materiotheme/assets/dist/main.js +++ b/web/themes/custom/materiotheme/assets/dist/main.js @@ -1595,7 +1595,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n})); /***/ ((__unused_webpack_module, exports, __webpack_require__) => { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.default = void 0;\n\nvar _restAxios = __webpack_require__(/*! vuejs/api/rest-axios */ \"./web/themes/custom/materiotheme/vuejs/api/rest-axios.js\");\n\nvar _maAxios = __webpack_require__(/*! vuejs/api/ma-axios */ \"./web/themes/custom/materiotheme/vuejs/api/ma-axios.js\");\n\nvar _querystringEs = _interopRequireDefault(__webpack_require__(/*! querystring-es3 */ \"./node_modules/querystring-es3/index.js\"));\n\nvar _materiauflaglistFragment = _interopRequireDefault(__webpack_require__(/*! vuejs/api/gql/materiauflaglist.fragment.gql */ \"./web/themes/custom/materiotheme/vuejs/api/gql/materiauflaglist.fragment.gql\"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\n// import { JSONAPI } from 'vuejs/api/json-axios'\nvar _default = {\n namespaced: true,\n // initial state\n state: {\n uid: null,\n // username: '',\n mail: '',\n csrf_token: null,\n logout_token: null,\n isloggedin: false,\n isAdmin: false,\n isAdherent: false,\n canSearch: false,\n roles: [],\n flagcolls: false,\n flagcollsLoadedItems: {},\n openedCollid: null\n },\n // getters\n getters: {},\n // mutations\n mutations: {\n SetCsrftoken: function SetCsrftoken(state, token) {\n console.log('SetCsrftoken', token);\n state.csrf_token = token;\n },\n setToken: function setToken(state, data) {\n state.uid = data.current_user.uid; // state.username = data.username;\n\n state.mail = data.current_user.mail;\n state.csrf_token = data.csrf_token;\n state.isloggedin = true;\n state.logout_token = data.logout_token;\n },\n setUid: function setUid(state, uid) {\n state.uid = uid;\n state.isloggedin = true;\n },\n setUser: function setUser(state, data) {\n state.mail = data.mail[0].value;\n state.uuid = data.uuid[0].value;\n },\n setRoles: function setRoles(state, roles) {\n console.log('User setRoles', roles);\n state.roles = [];\n\n for (var i = 0; i < roles.length; i++) {\n state.roles.push(roles[i].target_id);\n } // check if admin\n\n\n if (state.roles.indexOf('admin') !== -1 || state.roles.indexOf('root') !== -1) {\n // console.log('is admin');\n state.isAdmin = true;\n } // check if has access to search\n\n\n if (state.roles.indexOf('adherent') !== -1) {\n // console.log('is admin');\n state.canSearch = true;\n state.isAdherent = true;\n }\n },\n setLoggedOut: function setLoggedOut(state) {\n console.log('setLoggedOut state', state);\n state.uid = null;\n state.mail = '';\n state.csrf_token = null;\n state.isloggedin = false;\n state.logout_token = null;\n\n if (state.isAdmin) {\n // TODO: what if on a page where login is needed (as commerce checkout and cart)\n window.location.reload(true);\n }\n\n state.asAdmin = false;\n state.canSearch = false;\n },\n setFlagColls: function setFlagColls(state, flagcolls) {\n console.log('User pre setFlagColls', state.flagcolls);\n state.flagcolls = flagcolls; // console.log('User post setFlagColls', state.flagcolls)\n },\n openFlagColl: function openFlagColl(state, collid) {\n state.openedCollid = collid;\n },\n closeFlagColl: function closeFlagColl(state) {\n state.openedCollid = null;\n },\n setLoadedCollItems: function setLoadedCollItems(state, data) {\n console.log('setLoadedCollItems', data); // if no data, we are just calling the mutation to trigger the component update\n\n if (data) {\n state.flagcollsLoadedItems[data.collid] = data.items;\n }\n }\n },\n // actions\n actions: {\n userRegister: function userRegister(_ref, credentials) {\n var dispatch = _ref.dispatch,\n commit = _ref.commit,\n state = _ref.state;\n return new Promise(function (resolve) {\n _restAxios.REST.get('/session/token').then(function (_ref2) {\n var token = _ref2.token;\n commit('SetCsrftoken', token);\n\n _restAxios.REST.post('/user/register?_format=json', credentials, {\n 'X-CSRF-Token': state.csrftoken\n }).then(function (_ref3) {\n var data = _ref3.data;\n console.log('user REST registered', data);\n dispatch('userLogin', credentials).then(function () {\n resolve();\n });\n }).catch(function (error) {\n console.warn('Issue with register', error);\n Promise.reject(error);\n });\n });\n });\n },\n userLogin: function userLogin(_ref4, credentials) {\n var dispatch = _ref4.dispatch,\n state = _ref4.state;\n return new Promise(function (resolve, reject) {\n dispatch('getToken', credentials) // TODO: catch failed login\n .then(function () {\n dispatch('getUser').then(function (userdata) {\n console.log('User Loggedin');\n\n if (state.isAdmin) {\n window.location.reload(true);\n }\n\n resolve();\n });\n }).catch(function (error) {\n console.warn('Issue with Dispatch getToken', error);\n Promise.reject(error);\n });\n });\n },\n getToken: function getToken(_ref5, credentials) {\n var dispatch = _ref5.dispatch,\n commit = _ref5.commit,\n state = _ref5.state;\n return _restAxios.REST.post('/user/login?_format=json', credentials).then(function (_ref6) {\n var data = _ref6.data;\n console.log('user REST getToken data', data);\n commit('setToken', data);\n }).catch(function (error) {\n console.warn('Issue with getToken', error);\n Promise.reject(error);\n });\n },\n getUser: function getUser(_ref7) {\n var dispatch = _ref7.dispatch,\n commit = _ref7.commit,\n state = _ref7.state;\n return new Promise(function (resolve, reject) {\n _restAxios.REST.get('/session/token').then(function (_ref8) {\n var data = _ref8.data;\n console.log('csrftoken', data);\n commit('SetCsrftoken', data);\n console.log('state.csrf_token', state.csrf_token);\n var params = {\n token: state.csrf_token\n };\n\n _restAxios.REST.get(\"/user/\".concat(state.uid, \"?_format=json\"), params).then(function (_ref9) {\n var data = _ref9.data;\n console.log('user REST getUser data', data);\n console.log('roles', data.roles);\n commit('setUser', data);\n\n if (data.roles) {\n commit('setRoles', data.roles);\n }\n\n dispatch('getUserFlagColls');\n resolve();\n }).catch(function (error) {\n console.warn('Issue with getUser', error);\n Promise.reject(error);\n });\n });\n });\n },\n getUserFlagColls: function getUserFlagColls(_ref10) {\n var dispatch = _ref10.dispatch,\n commit = _ref10.commit,\n state = _ref10.state;\n // flags\n // REST.get('/flagging_collection/1?_format=json')\n // .then(( data ) => {\n // console.log('TEST FLAG REST data', data)\n // })\n // .catch(error => {\n // console.warn('Issue USER TEST FLAG REST', error)\n // Promise.reject(error)\n // })\n return _maAxios.MA.get('materio_flag/user_flagging_collections').then(function (_ref11) {\n var data = _ref11.data;\n console.log('user MA getFlags data', data);\n commit('setFlagColls', data);\n }).catch(function (error) {\n console.warn('Issue USER MA getFlags', error);\n Promise.reject(error);\n });\n },\n // https://drupal.stackexchange.com/questions/248539/cant-get-flagging-api-to-accept-post-request\n createFlagColl: function createFlagColl(_ref12, new_collection_name) {\n var dispatch = _ref12.dispatch,\n commit = _ref12.commit,\n state = _ref12.state;\n console.log('user createFlagColl', new_collection_name);\n return new Promise(function (resolve, reject) {\n var params = {\n name: new_collection_name\n };\n\n _maAxios.MA.post('materio_flag/create_user_flagging_collection', params).then(function (_ref13) {\n var data = _ref13.data;\n console.log('user MA createFlagColl data', data);\n\n if (data.status) {\n dispatch('getUserFlagColls').then(function () {\n resolve();\n });\n }\n }).catch(function (error) {\n console.warn('Issue USER MA createFlag', error);\n reject(error);\n });\n });\n },\n deleteFlagColl: function deleteFlagColl(_ref14, flagcollid) {\n var dispatch = _ref14.dispatch,\n commit = _ref14.commit,\n state = _ref14.state;\n console.log('user deleteFlagColl', flagcollid);\n return new Promise(function (resolve, reject) {\n var params = {\n flagcollid: flagcollid\n };\n\n _maAxios.MA.post('materio_flag/delete_user_flagging_collection', params).then(function (_ref15) {\n var data = _ref15.data;\n console.log('user MA deleteFlagColl data', data);\n dispatch('getUserFlagColls').then(function () {\n resolve();\n });\n }).catch(function (error) {\n console.warn('Issue USER MA createFlag', error);\n reject(error);\n });\n });\n },\n flagUnflag: function flagUnflag(_ref16, _ref17) {\n var dispatch = _ref16.dispatch,\n commit = _ref16.commit,\n state = _ref16.state;\n var action = _ref17.action,\n id = _ref17.id,\n collid = _ref17.collid;\n console.log('user flagUnflag', action, id, collid);\n return new Promise(function (resolve, reject) {\n var params = {\n flagid: state.flagcolls[collid].flag_id,\n id: id,\n flagcollid: collid\n };\n return _maAxios.MA.post(\"materio_flag/\".concat(action), params).then(function (_ref18) {\n var data = _ref18.data;\n console.log('user MA flag', data); // reload the fulllist of flagcolleciton\n\n dispatch('getUserFlagColls').then(function () {\n if (state.flagcolls[collid].items.length) {\n dispatch('loadMaterialsGQL', {\n ids: state.flagcolls[collid].items,\n gqlfragment: _materiauflaglistFragment.default,\n callBack: 'loadMaterialsCallBack',\n callBackArgs: {\n collid: collid\n }\n }).then(function () {\n resolve();\n }); // dispatch('loadMaterials', {\n // uuids: state.flagcolls[collid].items_uuids,\n // imgStyle: ['card_medium_half'],\n // callBack: 'loadMaterialsCallBack',\n // callBackArgs: { collid: collid }\n // }).then(() => {\n // resolve()\n // })\n } else {\n commit('setLoadedCollItems', {\n collid: collid,\n items: []\n });\n resolve();\n }\n });\n }).catch(function (error) {\n console.warn('Issue USER MA flagUnflag', error);\n });\n });\n },\n openFlagColl: function openFlagColl(_ref19, collid) {\n var commit = _ref19.commit,\n dispatch = _ref19.dispatch,\n state = _ref19.state;\n console.log('user openFlagColl', collid);\n commit('openFlagColl', collid);\n\n if (state.flagcolls[collid].items.length) {\n if (typeof state.flagcollsLoadedItems[collid] === 'undefined') {\n console.log('loading flagcoll items', state.flagcolls[collid]); // if no loadedItems, load them\n // loadMaterials is on mixins\n // https://github.com/huybuidac/vuex-extensions\n\n dispatch('loadMaterialsGQL', {\n ids: state.flagcolls[collid].items,\n gqlfragment: _materiauflaglistFragment.default,\n callBack: 'loadMaterialsCallBack',\n callBackArgs: {\n collid: collid\n }\n }); // dispatch('loadMaterials', {\n // uuids: state.flagcolls[collid].items_uuids,\n // imgStyle: ['card_medium_half'],\n // callBack: 'loadMaterialsCallBack',\n // callBackArgs: { collid: collid }\n // })\n } else {\n // call the mutation without data to only trigger the FlagCollection component update\n console.log('committing setLoadedCollItems without args');\n commit('setLoadedCollItems');\n }\n } else {\n commit('setLoadedCollItems', {\n collid: collid,\n items: []\n });\n }\n },\n loadMaterialsCallBack: function loadMaterialsCallBack(_ref20, _ref21) {\n var commit = _ref20.commit;\n var items = _ref21.items,\n callBackArgs = _ref21.callBackArgs;\n console.log('user loadMaterialsCallBack', items, callBackArgs);\n commit('setLoadedCollItems', {\n collid: callBackArgs.collid,\n items: items\n });\n },\n closeFlagColl: function closeFlagColl(_ref22) {\n var commit = _ref22.commit,\n dispatch = _ref22.dispatch;\n console.log('user closeFlagColl');\n commit('closeFlagColl');\n },\n userLogout: function userLogout(_ref23) {\n var commit = _ref23.commit,\n state = _ref23.state;\n\n var credentials = _querystringEs.default.stringify({\n token: state.csrf_token\n });\n\n _restAxios.REST.post('/user/logout', credentials).then(function (resp) {\n console.log('userLogout resp', resp);\n commit('setLoggedOut');\n }).catch(function (error) {\n console.warn('Issue with logout', error);\n Promise.reject(error);\n });\n }\n }\n};\nexports.default = _default;\n\n//# sourceURL=webpack://materio.com/./web/themes/custom/materiotheme/vuejs/store/modules/user.js?"); +eval("\n\nObject.defineProperty(exports, \"__esModule\", ({\n value: true\n}));\nexports.default = void 0;\n\nvar _restAxios = __webpack_require__(/*! vuejs/api/rest-axios */ \"./web/themes/custom/materiotheme/vuejs/api/rest-axios.js\");\n\nvar _maAxios = __webpack_require__(/*! vuejs/api/ma-axios */ \"./web/themes/custom/materiotheme/vuejs/api/ma-axios.js\");\n\nvar _querystringEs = _interopRequireDefault(__webpack_require__(/*! querystring-es3 */ \"./node_modules/querystring-es3/index.js\"));\n\nvar _materiauflaglistFragment = _interopRequireDefault(__webpack_require__(/*! vuejs/api/gql/materiauflaglist.fragment.gql */ \"./web/themes/custom/materiotheme/vuejs/api/gql/materiauflaglist.fragment.gql\"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\n// import { JSONAPI } from 'vuejs/api/json-axios'\n// import router from 'vuejs/route' // this is not working\nvar _default = {\n namespaced: true,\n // router,\n // initial state\n state: {\n uid: null,\n // username: '',\n mail: '',\n csrf_token: null,\n logout_token: null,\n isloggedin: false,\n isAdmin: false,\n isAdherent: false,\n canSearch: false,\n roles: [],\n flagcolls: false,\n flagcollsLoadedItems: {},\n openedCollid: null\n },\n // getters\n getters: {},\n // mutations\n mutations: {\n SetCsrftoken: function SetCsrftoken(state, token) {\n console.log('SetCsrftoken', token);\n state.csrf_token = token;\n },\n setToken: function setToken(state, data) {\n state.uid = data.current_user.uid; // state.username = data.username;\n\n state.mail = data.current_user.mail;\n state.csrf_token = data.csrf_token;\n state.isloggedin = true;\n state.logout_token = data.logout_token;\n },\n setUid: function setUid(state, uid) {\n state.uid = uid;\n state.isloggedin = true;\n },\n setUser: function setUser(state, data) {\n state.mail = data.mail[0].value;\n state.uuid = data.uuid[0].value;\n },\n setRoles: function setRoles(state, roles) {\n console.log('User setRoles', roles);\n state.roles = [];\n\n for (var i = 0; i < roles.length; i++) {\n state.roles.push(roles[i].target_id);\n } // check if admin\n\n\n if (state.roles.indexOf('admin') !== -1 || state.roles.indexOf('root') !== -1) {\n // console.log('is admin');\n state.isAdmin = true;\n } // check if has access to search\n\n\n if (state.roles.indexOf('adherent') !== -1) {\n // console.log('is admin');\n state.canSearch = true;\n state.isAdherent = true;\n }\n },\n setLoggedOut: function setLoggedOut(state) {\n console.log('setLoggedOut state', state);\n state.uid = null;\n state.mail = '';\n state.csrf_token = null;\n state.isloggedin = false;\n state.logout_token = null;\n state.asAdmin = false;\n state.canSearch = false; // if (state.isAdmin) {\n // // TODO: what if on a page where login is needed (as commerce checkout and cart)\n // window.location.reload(true)\n // } else {\n //\n // // return systematically to home page\n // this.$router.push({\n // name:`home`\n // // params: { alias:this.alias }\n // // query: { nid: this.item.nid }\n // // meta: { uuid:this.item.uuid },\n // })\n // }\n // redirect to home page in every case\n\n window.location = window.location.origin;\n },\n setFlagColls: function setFlagColls(state, flagcolls) {\n console.log('User pre setFlagColls', state.flagcolls);\n state.flagcolls = flagcolls; // console.log('User post setFlagColls', state.flagcolls)\n },\n openFlagColl: function openFlagColl(state, collid) {\n state.openedCollid = collid;\n },\n closeFlagColl: function closeFlagColl(state) {\n state.openedCollid = null;\n },\n setLoadedCollItems: function setLoadedCollItems(state, data) {\n console.log('setLoadedCollItems', data); // if no data, we are just calling the mutation to trigger the component update\n\n if (data) {\n state.flagcollsLoadedItems[data.collid] = data.items;\n }\n }\n },\n // actions\n actions: {\n userRegister: function userRegister(_ref, credentials) {\n var dispatch = _ref.dispatch,\n commit = _ref.commit,\n state = _ref.state;\n return new Promise(function (resolve) {\n _restAxios.REST.get('/session/token').then(function (_ref2) {\n var token = _ref2.token;\n commit('SetCsrftoken', token);\n\n _restAxios.REST.post('/user/register?_format=json', credentials, {\n 'X-CSRF-Token': state.csrftoken\n }).then(function (_ref3) {\n var data = _ref3.data;\n console.log('user REST registered', data);\n dispatch('userLogin', credentials).then(function () {\n resolve();\n });\n }).catch(function (error) {\n console.warn('Issue with register', error);\n Promise.reject(error);\n });\n });\n });\n },\n userLogin: function userLogin(_ref4, credentials) {\n var dispatch = _ref4.dispatch,\n state = _ref4.state;\n return new Promise(function (resolve, reject) {\n dispatch('getToken', credentials) // TODO: catch failed login\n .then(function () {\n dispatch('getUser').then(function (userdata) {\n console.log('User Loggedin');\n\n if (state.isAdmin) {\n window.location.reload(true);\n }\n\n resolve();\n });\n }).catch(function (error) {\n console.warn('Issue with Dispatch getToken', error);\n Promise.reject(error);\n });\n });\n },\n getToken: function getToken(_ref5, credentials) {\n var dispatch = _ref5.dispatch,\n commit = _ref5.commit,\n state = _ref5.state;\n return _restAxios.REST.post('/user/login?_format=json', credentials).then(function (_ref6) {\n var data = _ref6.data;\n console.log('user REST getToken data', data);\n commit('setToken', data);\n }).catch(function (error) {\n console.warn('Issue with getToken', error);\n Promise.reject(error);\n });\n },\n getUser: function getUser(_ref7) {\n var dispatch = _ref7.dispatch,\n commit = _ref7.commit,\n state = _ref7.state;\n return new Promise(function (resolve, reject) {\n _restAxios.REST.get('/session/token').then(function (_ref8) {\n var data = _ref8.data;\n console.log('csrftoken', data);\n commit('SetCsrftoken', data);\n console.log('state.csrf_token', state.csrf_token);\n var params = {\n token: state.csrf_token\n };\n\n _restAxios.REST.get(\"/user/\".concat(state.uid, \"?_format=json\"), params).then(function (_ref9) {\n var data = _ref9.data;\n console.log('user REST getUser data', data);\n console.log('roles', data.roles);\n commit('setUser', data);\n\n if (data.roles) {\n commit('setRoles', data.roles);\n }\n\n dispatch('getUserFlagColls');\n resolve();\n }).catch(function (error) {\n console.warn('Issue with getUser', error);\n Promise.reject(error);\n });\n });\n });\n },\n getUserFlagColls: function getUserFlagColls(_ref10) {\n var dispatch = _ref10.dispatch,\n commit = _ref10.commit,\n state = _ref10.state;\n // flags\n // REST.get('/flagging_collection/1?_format=json')\n // .then(( data ) => {\n // console.log('TEST FLAG REST data', data)\n // })\n // .catch(error => {\n // console.warn('Issue USER TEST FLAG REST', error)\n // Promise.reject(error)\n // })\n return _maAxios.MA.get('materio_flag/user_flagging_collections').then(function (_ref11) {\n var data = _ref11.data;\n console.log('user MA getFlags data', data);\n commit('setFlagColls', data);\n }).catch(function (error) {\n console.warn('Issue USER MA getFlags', error);\n Promise.reject(error);\n });\n },\n // https://drupal.stackexchange.com/questions/248539/cant-get-flagging-api-to-accept-post-request\n createFlagColl: function createFlagColl(_ref12, new_collection_name) {\n var dispatch = _ref12.dispatch,\n commit = _ref12.commit,\n state = _ref12.state;\n console.log('user createFlagColl', new_collection_name);\n return new Promise(function (resolve, reject) {\n var params = {\n name: new_collection_name\n };\n\n _maAxios.MA.post('materio_flag/create_user_flagging_collection', params).then(function (_ref13) {\n var data = _ref13.data;\n console.log('user MA createFlagColl data', data);\n\n if (data.status) {\n dispatch('getUserFlagColls').then(function () {\n resolve();\n });\n }\n }).catch(function (error) {\n console.warn('Issue USER MA createFlag', error);\n reject(error);\n });\n });\n },\n deleteFlagColl: function deleteFlagColl(_ref14, flagcollid) {\n var dispatch = _ref14.dispatch,\n commit = _ref14.commit,\n state = _ref14.state;\n console.log('user deleteFlagColl', flagcollid);\n return new Promise(function (resolve, reject) {\n var params = {\n flagcollid: flagcollid\n };\n\n _maAxios.MA.post('materio_flag/delete_user_flagging_collection', params).then(function (_ref15) {\n var data = _ref15.data;\n console.log('user MA deleteFlagColl data', data);\n dispatch('getUserFlagColls').then(function () {\n resolve();\n });\n }).catch(function (error) {\n console.warn('Issue USER MA createFlag', error);\n reject(error);\n });\n });\n },\n flagUnflag: function flagUnflag(_ref16, _ref17) {\n var dispatch = _ref16.dispatch,\n commit = _ref16.commit,\n state = _ref16.state;\n var action = _ref17.action,\n id = _ref17.id,\n collid = _ref17.collid;\n console.log('user flagUnflag', action, id, collid);\n return new Promise(function (resolve, reject) {\n var params = {\n flagid: state.flagcolls[collid].flag_id,\n id: id,\n flagcollid: collid\n };\n return _maAxios.MA.post(\"materio_flag/\".concat(action), params).then(function (_ref18) {\n var data = _ref18.data;\n console.log('user MA flag', data); // reload the fulllist of flagcolleciton\n\n dispatch('getUserFlagColls').then(function () {\n if (state.flagcolls[collid].items.length) {\n dispatch('loadMaterialsGQL', {\n ids: state.flagcolls[collid].items,\n gqlfragment: _materiauflaglistFragment.default,\n callBack: 'loadMaterialsCallBack',\n callBackArgs: {\n collid: collid\n }\n }).then(function () {\n resolve();\n }); // dispatch('loadMaterials', {\n // uuids: state.flagcolls[collid].items_uuids,\n // imgStyle: ['card_medium_half'],\n // callBack: 'loadMaterialsCallBack',\n // callBackArgs: { collid: collid }\n // }).then(() => {\n // resolve()\n // })\n } else {\n commit('setLoadedCollItems', {\n collid: collid,\n items: []\n });\n resolve();\n }\n });\n }).catch(function (error) {\n console.warn('Issue USER MA flagUnflag', error);\n });\n });\n },\n openFlagColl: function openFlagColl(_ref19, collid) {\n var commit = _ref19.commit,\n dispatch = _ref19.dispatch,\n state = _ref19.state;\n console.log('user openFlagColl', collid);\n commit('openFlagColl', collid);\n\n if (state.flagcolls[collid].items.length) {\n if (typeof state.flagcollsLoadedItems[collid] === 'undefined') {\n console.log('loading flagcoll items', state.flagcolls[collid]); // if no loadedItems, load them\n // loadMaterials is on mixins\n // https://github.com/huybuidac/vuex-extensions\n\n dispatch('loadMaterialsGQL', {\n ids: state.flagcolls[collid].items,\n gqlfragment: _materiauflaglistFragment.default,\n callBack: 'loadMaterialsCallBack',\n callBackArgs: {\n collid: collid\n }\n }); // dispatch('loadMaterials', {\n // uuids: state.flagcolls[collid].items_uuids,\n // imgStyle: ['card_medium_half'],\n // callBack: 'loadMaterialsCallBack',\n // callBackArgs: { collid: collid }\n // })\n } else {\n // call the mutation without data to only trigger the FlagCollection component update\n console.log('committing setLoadedCollItems without args');\n commit('setLoadedCollItems');\n }\n } else {\n commit('setLoadedCollItems', {\n collid: collid,\n items: []\n });\n }\n },\n loadMaterialsCallBack: function loadMaterialsCallBack(_ref20, _ref21) {\n var commit = _ref20.commit;\n var items = _ref21.items,\n callBackArgs = _ref21.callBackArgs;\n console.log('user loadMaterialsCallBack', items, callBackArgs);\n commit('setLoadedCollItems', {\n collid: callBackArgs.collid,\n items: items\n });\n },\n closeFlagColl: function closeFlagColl(_ref22) {\n var commit = _ref22.commit,\n dispatch = _ref22.dispatch;\n console.log('user closeFlagColl');\n commit('closeFlagColl');\n },\n userLogout: function userLogout(_ref23) {\n var commit = _ref23.commit,\n state = _ref23.state;\n\n var credentials = _querystringEs.default.stringify({\n token: state.csrf_token\n });\n\n _restAxios.REST.post('/user/logout', credentials).then(function (resp) {\n console.log('userLogout resp', resp);\n commit('setLoggedOut');\n }).catch(function (error) {\n console.warn('Issue with logout', error);\n Promise.reject(error);\n });\n }\n }\n};\nexports.default = _default;\n\n//# sourceURL=webpack://materio.com/./web/themes/custom/materiotheme/vuejs/store/modules/user.js?"); /***/ }), diff --git a/web/themes/custom/materiotheme/vuejs/store/modules/user.js b/web/themes/custom/materiotheme/vuejs/store/modules/user.js index 30527505..c741459f 100644 --- a/web/themes/custom/materiotheme/vuejs/store/modules/user.js +++ b/web/themes/custom/materiotheme/vuejs/store/modules/user.js @@ -5,8 +5,11 @@ import qs from 'querystring-es3' import materiauGQL from 'vuejs/api/gql/materiauflaglist.fragment.gql' +// import router from 'vuejs/route' // this is not working + export default { namespaced: true, + // router, // initial state state: { @@ -78,12 +81,24 @@ export default { state.csrf_token = null state.isloggedin = false state.logout_token = null - if (state.isAdmin) { - // TODO: what if on a page where login is needed (as commerce checkout and cart) - window.location.reload(true) - } state.asAdmin = false state.canSearch = false + // if (state.isAdmin) { + // // TODO: what if on a page where login is needed (as commerce checkout and cart) + // window.location.reload(true) + // } else { + // + // // return systematically to home page + // this.$router.push({ + // name:`home` + // // params: { alias:this.alias } + // // query: { nid: this.item.nid } + // // meta: { uuid:this.item.uuid }, + // }) + // } + + // redirect to home page in every case + window.location = window.location.origin }, setFlagColls (state, flagcolls) { console.log('User pre setFlagColls', state.flagcolls)