diff --git a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/_store.js b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/_store.js index a451cb19..6a5c3e92 100644 --- a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/_store.js +++ b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/_store.js @@ -1,12 +1,28 @@ -import Vue from 'vue'; -import Vuex from 'vuex'; -import axios from 'axios'; +import Vue from 'vue' +import Vuex from 'vuex' +import axios from 'axios' +import EventBus from '../_bus' + +const configElement = document.getElementById('appconfig'); +const config = JSON.parse(configElement.innerHTML); + +axios.defaults.headers.common['Accept'] = 'application/json'; +axios.defaults.headers.put['Content-Type'] = 'application/json'; +axios.defaults.baseURL = config.myEpApiBaseUrl; + +const createAuthenticatingClient = () => { + return axios.create({ + headers: { + 'X-Auth-Token': sessionStorage.getItem('token') + }, + }); +}; Vue.use(Vuex); export default new Vuex.Store({ state: { - config: {}, + config: config, loading: false, loggedIn: !!sessionStorage.getItem('token'), countries: [] @@ -29,9 +45,6 @@ export default new Vuex.Store({ }, setCountries (state, countries) { state.countries = countries; - }, - setConfig (state, config) { - state.config = config; } }, actions: { @@ -89,81 +102,82 @@ export default new Vuex.Store({ }, loadAddress ({ commit }) { commit('loadingBegin'); - return axios({ - url: '/api/addresses', - headers: { - 'x-auth-token': sessionStorage.getItem('token') - } - }).then((response) => { - commit('loadingFinish'); - return response.data[0]; - }).catch((error) => { - commit('loadingFinish'); - throw error; - }); + + const client = createAuthenticatingClient(); + + return client.get('/api/addresses') + .then((response) => { + commit('loadingFinish'); + return response.data[0]; + }).catch((error) => { + commit('loadingFinish'); + commit('logout'); + EventBus.$emit('forcedLogout'); + throw error; + }); }, saveAddress ({ commit }, data) { commit('loadingBegin'); - return axios({ - url: '/api/addresses/' + data.id, - headers: { - 'x-auth-token': sessionStorage.getItem('token') - }, - method: 'PUT', - data: data - }).then(() => { - commit('loadingFinish'); - }) - .catch((error) => { - commit('loadingFinish'); - throw error; - }); + + const client = createAuthenticatingClient(); + + return client.put('/api/addresses/' + data.id, data) + .then(() => { + commit('loadingFinish'); + }) + .catch((error) => { + commit('loadingFinish'); + commit('logout'); + EventBus.$emit('forcedLogout'); + throw error; + }); }, loadEvents ({ commit }) { commit('loadingBegin'); - return axios({ - url: '/api/events', - headers: { - 'x-auth-token': sessionStorage.getItem('token') - } - }).then((response) => { + + const client = createAuthenticatingClient(); + + return client.get('/api/events') + .then((response) => { commit('loadingFinish'); return response.data; }).catch((error) => { commit('loadingFinish'); + commit('logout'); + EventBus.$emit('forcedLogout'); throw error; }); }, loadCrmData ({ commit }) { commit('loadingBegin'); - return axios({ - url: '/api/crm-selections', - headers: { - 'x-auth-token': sessionStorage.getItem('token') - } - }).then((response) => { - commit('loadingFinish'); - return response.data[0]; - }).catch((error) => { - commit('loadingFinish'); - throw error; - }); + + const client = createAuthenticatingClient(); + + return client.get('/api/crm-selections') + .then((response) => { + commit('loadingFinish'); + return response.data[0]; + }).catch((error) => { + commit('loadingFinish'); + commit('logout'); + EventBus.$emit('forcedLogout'); + throw error; + }); }, saveCrmData ({ commit }, data) { commit('loadingBegin'); - return axios({ - url: '/api/crm-selections/' + data.id, - headers: { - 'x-auth-token': sessionStorage.getItem('token') - }, - method: 'PUT', - data: data - }).then(() => { - commit('loadingFinish'); - }).catch((error) => { - commit('loadingFinish'); - throw error; - }); + + const client = createAuthenticatingClient(); + + return client.put('/api/crm-selections/' + data.id, data) + .then(() => { + commit('loadingFinish'); + }).catch((error) => { + commit('loadingFinish'); + commit('logout'); + EventBus.$emit('forcedLogout'); + throw error; + }); } }, getters: { diff --git a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Address.vue b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Address.vue index 4d08fb53..d2264b38 100644 --- a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Address.vue +++ b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Address.vue @@ -7,7 +7,7 @@ {{ message }} - +
@@ -69,7 +69,7 @@ Land:
@@ -143,12 +143,6 @@ } }, computed: { - loaderUrl () { - return this.$store.state.config.loaderUrl; - }, - countries () { - return this.$store.state.countries; - }, loading () { return this.$store.state.loading; } diff --git a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/App.vue b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/App.vue index cdc355a1..d73f8f5f 100644 --- a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/App.vue +++ b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/App.vue @@ -11,20 +11,9 @@ diff --git a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/CrmData.vue b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/CrmData.vue index b51f42c4..299e48fd 100644 --- a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/CrmData.vue +++ b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/CrmData.vue @@ -7,7 +7,7 @@ {{ message }} - +

Selektionsmerkmale

@@ -84,9 +84,6 @@ } }, computed: { - loaderUrl () { - return this.$store.state.config.loaderUrl; - }, loading () { return this.$store.state.loading; } diff --git a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Events.vue b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Events.vue index 961778cf..01c59593 100644 --- a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Events.vue +++ b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Events.vue @@ -7,7 +7,7 @@ {{ message }}
- +
@@ -89,9 +89,6 @@ } }, computed: { - loaderUrl () { - return this.$store.state.config.loaderUrl; - }, loading () { return this.$store.state.loading; } diff --git a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Login.vue b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Login.vue index 3fbe7df9..8b078fcd 100644 --- a/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Login.vue +++ b/web/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/components/Login.vue @@ -1,6 +1,6 @@