display admin link if admin role
This commit is contained in:
parent
6b34adabb3
commit
ebfd405153
|
@ -429,7 +429,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = void 0;\n\nvar _vuex = __webpack_require__(/*! vuex */ \"./node_modules/vuex/dist/vuex.esm.js\");\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nvar _default = {\n // data () {\n // return {\n // mail: \"Hello User!\"\n // }\n // },\n computed: _objectSpread({}, (0, _vuex.mapState)({\n mail: function mail(state) {\n return state.User.mail;\n }\n })),\n methods: _objectSpread({}, (0, _vuex.mapActions)({\n userLogout: 'User/userLogout'\n }), {\n onLogout: function onLogout() {\n this.userLogout();\n }\n })\n};\nexports.default = _default;\n\n//# sourceURL=webpack:///./web/themes/custom/materiotheme/vuejs/components/User/UserTools.vue?./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options");
|
eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\nexports.default = void 0;\n\nvar _vuex = __webpack_require__(/*! vuex */ \"./node_modules/vuex/dist/vuex.esm.js\");\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nvar _default = {\n // data () {\n // return {\n // mail: \"Hello User!\"\n // }\n // },\n computed: _objectSpread({}, (0, _vuex.mapState)({\n mail: function mail(state) {\n return state.User.mail;\n },\n isAdmin: function isAdmin(state) {\n return state.User.isAdmin;\n }\n })),\n methods: _objectSpread({}, (0, _vuex.mapActions)({\n userLogout: 'User/userLogout'\n }), {\n onLogout: function onLogout() {\n this.userLogout();\n }\n })\n};\nexports.default = _default;\n\n//# sourceURL=webpack:///./web/themes/custom/materiotheme/vuejs/components/User/UserTools.vue?./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options");
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
@ -580,7 +580,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
|
||||||
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"render\", function() { return render; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"staticRenderFns\", function() { return staticRenderFns; });\nvar render = function() {\n var _vm = this\n var _h = _vm.$createElement\n var _c = _vm._self._c || _h\n return _c(\"div\", { attrs: { id: \"user-tools\" } }, [\n _c(\"h4\", [_vm._v(_vm._s(_vm.mail))]),\n _vm._v(\" \"),\n _c(\n \"a\",\n {\n attrs: { href: \"/user/logout\" },\n on: {\n click: function($event) {\n $event.preventDefault()\n return _vm.onLogout()\n }\n }\n },\n [_vm._v(\"\\n logout\\n \")]\n )\n ])\n}\nvar staticRenderFns = []\nrender._withStripped = true\n\n\n\n//# sourceURL=webpack:///./web/themes/custom/materiotheme/vuejs/components/User/UserTools.vue?./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options");
|
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"render\", function() { return render; });\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"staticRenderFns\", function() { return staticRenderFns; });\nvar render = function() {\n var _vm = this\n var _h = _vm.$createElement\n var _c = _vm._self._c || _h\n return _c(\"div\", { attrs: { id: \"user-tools\" } }, [\n _c(\"h4\", [_vm._v(_vm._s(_vm.mail))]),\n _vm._v(\" \"),\n _vm.isAdmin\n ? _c(\"a\", { attrs: { href: \"/admin/content/materials\" } }, [\n _vm._v(\"\\n Admin\\n \")\n ])\n : _vm._e(),\n _vm._v(\" \"),\n _c(\n \"a\",\n {\n attrs: { href: \"/user/logout\" },\n on: {\n click: function($event) {\n $event.preventDefault()\n return _vm.onLogout()\n }\n }\n },\n [_vm._v(\"\\n logout\\n \")]\n )\n ])\n}\nvar staticRenderFns = []\nrender._withStripped = true\n\n\n\n//# sourceURL=webpack:///./web/themes/custom/materiotheme/vuejs/components/User/UserTools.vue?./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options");
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
@ -866,7 +866,7 @@ eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n
|
||||||
/***/ (function(module, exports, __webpack_require__) {
|
/***/ (function(module, exports, __webpack_require__) {
|
||||||
|
|
||||||
"use strict";
|
"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 _jsonAxios = __webpack_require__(/*! vuejs/api/json-axios */ \"./web/themes/custom/materiotheme/vuejs/api/json-axios.js\");\n\nvar _querystring = _interopRequireDefault(__webpack_require__(/*! querystring */ \"./node_modules/querystring-es3/index.js\"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar _default = {\n namespaced: true,\n // initial state\n state: {\n uid: null,\n // username: '',\n mail: '',\n token: null,\n logout_token: null,\n isloggedin: false\n },\n // getters\n getters: {},\n // mutations\n mutations: {\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.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 setLoggedOut: function setLoggedOut(state) {\n state.uid = null;\n state.mail = '';\n state.token = null;\n state.isloggedin = false;\n state.logout_token = null;\n }\n },\n // actions\n actions: {\n getToken: function getToken(_ref, credentials) {\n var dispatch = _ref.dispatch,\n commit = _ref.commit,\n state = _ref.state;\n\n _restAxios.REST.post('/user/login?_format=json', credentials).then(function (_ref2) {\n var data = _ref2.data;\n console.log('user getToken data', data);\n commit('setToken', data);\n dispatch('getUser');\n }).catch(function (error) {\n console.warn('Issue with login', error);\n Promise.reject(error);\n });\n },\n getUser: function getUser(_ref3) {\n var commit = _ref3.commit,\n state = _ref3.state;\n var params = {\n token: state.token\n };\n\n _restAxios.REST.get(\"/user/\".concat(state.uid, \"?_format=json\"), params).then(function (_ref4) {\n var data = _ref4.data;\n console.log('user REST getUser data', data);\n console.log('roles', data['roles']);\n commit('setUser', data);\n\n _jsonAxios.JSONAPI.get(\"/user/user/\".concat(state.uuid, \"?include=roles\")).then(function (_ref5) {\n var data = _ref5.data;\n console.log('user JSONAPI getUser data', data);\n }).catch(function (error) {\n console.warn('Issue with getUser', error);\n Promise.reject(error);\n });\n }).catch(function (error) {\n console.warn('Issue with getUser', error);\n Promise.reject(error);\n });\n },\n userLogout: function userLogout(_ref6) {\n var commit = _ref6.commit,\n state = _ref6.state;\n\n var credentials = _querystring.default.stringify({\n token: state.token\n });\n\n _restAxios.REST.post('/user/logout', credentials).then(function (resp) {\n console.log('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:///./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 _jsonAxios = __webpack_require__(/*! vuejs/api/json-axios */ \"./web/themes/custom/materiotheme/vuejs/api/json-axios.js\");\n\nvar _querystring = _interopRequireDefault(__webpack_require__(/*! querystring */ \"./node_modules/querystring-es3/index.js\"));\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nvar _default = {\n namespaced: true,\n // initial state\n state: {\n uid: null,\n // username: '',\n mail: '',\n token: null,\n logout_token: null,\n isloggedin: false,\n isAdmin: false\n },\n // getters\n getters: {},\n // mutations\n mutations: {\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.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 state.roles = [];\n\n for (var i = 0; i < roles.length; i++) {\n state.roles.push(roles[i].target_id);\n }\n\n if (state.roles.indexOf('admin') != -1) {\n console.log('is admin');\n state.isAdmin = true;\n }\n },\n setLoggedOut: function setLoggedOut(state) {\n state.uid = null;\n state.mail = '';\n state.token = null;\n state.isloggedin = false;\n state.asAdmin = false;\n state.logout_token = null;\n }\n },\n // actions\n actions: {\n getToken: function getToken(_ref, credentials) {\n var dispatch = _ref.dispatch,\n commit = _ref.commit,\n state = _ref.state;\n\n _restAxios.REST.post('/user/login?_format=json', credentials).then(function (_ref2) {\n var data = _ref2.data;\n console.log('user getToken data', data);\n commit('setToken', data);\n dispatch('getUser');\n }).catch(function (error) {\n console.warn('Issue with login', error);\n Promise.reject(error);\n });\n },\n getUser: function getUser(_ref3) {\n var dispatch = _ref3.dispatch,\n commit = _ref3.commit,\n state = _ref3.state;\n var params = {\n token: state.token\n };\n\n _restAxios.REST.get(\"/user/\".concat(state.uid, \"?_format=json\"), params).then(function (_ref4) {\n var data = _ref4.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); // dispatch('checkLoginRole')\n } // dispatch('checkLoginRole')\n // JSONAPI.get(`/user/user/${state.uuid}?include=roles`)\n // .then(({ data }) => {\n // console.log('user JSONAPI getUser data', data)\n // })\n // .catch(( error ) => {\n // console.warn('Issue with getUser', error)\n // Promise.reject(error)\n // })\n\n }).catch(function (error) {\n console.warn('Issue with getUser', error);\n Promise.reject(error);\n });\n },\n // checkLoginRole ({ commit, state }){\n // console.log('checkLoginRole', state.roles, state.roles.indexOf('admin'))\n // if(state.roles.indexOf('admin') != -1){\n // console.log('is admin')\n // window.\n // }\n // },\n userLogout: function userLogout(_ref5) {\n var commit = _ref5.commit,\n state = _ref5.state;\n\n var credentials = _querystring.default.stringify({\n token: state.token\n });\n\n _restAxios.REST.post('/user/logout', credentials).then(function (resp) {\n console.log('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:///./web/themes/custom/materiotheme/vuejs/store/modules/user.js?");
|
||||||
|
|
||||||
/***/ })
|
/***/ })
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
<template lang="html">
|
<template lang="html">
|
||||||
<div id="user-tools">
|
<div id="user-tools">
|
||||||
<h4>{{ mail }}</h4>
|
<h4>{{ mail }}</h4>
|
||||||
|
<a href="/admin/content/materials"
|
||||||
|
v-if="isAdmin"
|
||||||
|
>
|
||||||
|
Admin
|
||||||
|
</a>
|
||||||
<a href="/user/logout"
|
<a href="/user/logout"
|
||||||
@click.prevent="onLogout()"
|
@click.prevent="onLogout()"
|
||||||
>
|
>
|
||||||
|
@ -20,7 +25,8 @@ export default {
|
||||||
// },
|
// },
|
||||||
computed: {
|
computed: {
|
||||||
...mapState({
|
...mapState({
|
||||||
mail: state => state.User.mail
|
mail: state => state.User.mail,
|
||||||
|
isAdmin: state => state.User.isAdmin
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -12,7 +12,8 @@ export default {
|
||||||
mail:'',
|
mail:'',
|
||||||
token: null,
|
token: null,
|
||||||
logout_token: null,
|
logout_token: null,
|
||||||
isloggedin: false
|
isloggedin: false,
|
||||||
|
isAdmin: false
|
||||||
},
|
},
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
|
@ -36,11 +37,22 @@ export default {
|
||||||
state.mail = data.mail[0].value
|
state.mail = data.mail[0].value
|
||||||
state.uuid = data.uuid[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) {
|
setLoggedOut (state) {
|
||||||
state.uid= null
|
state.uid= null
|
||||||
state.mail = ''
|
state.mail = ''
|
||||||
state.token = null
|
state.token = null
|
||||||
state.isloggedin = false
|
state.isloggedin = false
|
||||||
|
state.asAdmin = false
|
||||||
state.logout_token = null
|
state.logout_token = null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -59,29 +71,41 @@ export default {
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getUser ({ commit, state }) {
|
getUser ({ dispatch, commit, state }) {
|
||||||
let params = {
|
let params = {
|
||||||
token: state.token
|
token: state.token
|
||||||
}
|
}
|
||||||
REST.get(`/user/${state.uid}?_format=json`, params)
|
REST.get(`/user/${state.uid}?_format=json`, params)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
console.log('user REST getUser data', data)
|
console.log('user REST getUser data', data)
|
||||||
console.log('roles', data['roles']);
|
console.log('roles', data['roles'])
|
||||||
commit('setUser', data)
|
commit('setUser', data)
|
||||||
JSONAPI.get(`/user/user/${state.uuid}?include=roles`)
|
if(data.roles){
|
||||||
.then(({ data }) => {
|
commit('setRoles', data.roles)
|
||||||
console.log('user JSONAPI getUser data', data)
|
// dispatch('checkLoginRole')
|
||||||
})
|
}
|
||||||
.catch(( error ) => {
|
// dispatch('checkLoginRole')
|
||||||
console.warn('Issue with getUser', error)
|
// JSONAPI.get(`/user/user/${state.uuid}?include=roles`)
|
||||||
Promise.reject(error)
|
// .then(({ data }) => {
|
||||||
})
|
// console.log('user JSONAPI getUser data', data)
|
||||||
|
// })
|
||||||
|
// .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)
|
||||||
Promise.reject(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 }) {
|
userLogout ({ commit, state }) {
|
||||||
let credentials = qs.stringify({
|
let credentials = qs.stringify({
|
||||||
token: state.token
|
token: state.token
|
||||||
|
|
Loading…
Reference in New Issue