Finalize axios replacement in MyE&P SPA
This commit is contained in:
@@ -83,6 +83,10 @@
|
||||
this.picker.setDate(new Date(this.userData.dateOfBirth), true);
|
||||
this.$emit('loaded')
|
||||
})
|
||||
.catch(() => {
|
||||
this.logout()
|
||||
this.$router.push({name: 'login'})
|
||||
})
|
||||
},
|
||||
mounted () {
|
||||
Vue.nextTick(() => {
|
||||
@@ -97,7 +101,7 @@
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(['alert']),
|
||||
...mapMutations(['logout', 'alert']),
|
||||
...mapActions(['loadAddress', 'saveAddress']),
|
||||
save () {
|
||||
this.formErrors = {}
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
},
|
||||
methods: {
|
||||
...mapMutations(['alert']),
|
||||
...mapActions(['loadCountries']),
|
||||
...mapActions(['login', 'resetPassword', 'loadCountries']),
|
||||
toggleMode () {
|
||||
this.mode = this.mode === 'login' ? 'reset' : 'login';
|
||||
this.password = ''
|
||||
@@ -74,12 +74,12 @@
|
||||
submit () {
|
||||
this.message = '';
|
||||
if (this.mode === 'login') {
|
||||
this.login()
|
||||
this.performLogin()
|
||||
} else {
|
||||
this.resetPassword()
|
||||
this.performPasswordReset()
|
||||
}
|
||||
},
|
||||
login () {
|
||||
performLogin () {
|
||||
this.formErrors = {};
|
||||
if (!this.email || !this.password) {
|
||||
this.alert({
|
||||
@@ -88,18 +88,21 @@
|
||||
});
|
||||
return
|
||||
}
|
||||
this.$store.dispatch('login', {
|
||||
this.login({
|
||||
email: this.email,
|
||||
password: this.password
|
||||
}).then(() => {
|
||||
this.loadCountries()
|
||||
.then(() => {
|
||||
this.$router.replace({ name: 'address' })
|
||||
this.$router.push({ name: 'address' })
|
||||
})
|
||||
}).catch(error => {
|
||||
}).finally(() => {
|
||||
this.email = ''
|
||||
this.password = ''
|
||||
})
|
||||
},
|
||||
resetPassword () {
|
||||
performPasswordReset () {
|
||||
this.formErrors = {};
|
||||
if (!this.email) {
|
||||
this.alert({
|
||||
@@ -108,9 +111,8 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
this.$store.dispatch('resetPassword',
|
||||
this.email
|
||||
).then(response => {
|
||||
this.resetPassword(this.email)
|
||||
.then(response => {
|
||||
this.email = '';
|
||||
if (response.data.success) {
|
||||
this.alert({
|
||||
|
||||
@@ -15,4 +15,12 @@ function checkStatus(response) {
|
||||
}
|
||||
}
|
||||
|
||||
export { checkStatus, defaultOptions }
|
||||
function handleError() {
|
||||
commit('alert', {
|
||||
message: 'Es ist ein Fehler aufgetreten :(',
|
||||
success: false,
|
||||
})
|
||||
throw error
|
||||
}
|
||||
|
||||
export { checkStatus, handleError, defaultOptions }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import { checkStatus, defaultOptions } from '../api'
|
||||
import { checkStatus, handleError, defaultOptions } from '../api'
|
||||
|
||||
const configElement = document.getElementById('appconfig')
|
||||
const config = JSON.parse(configElement.innerHTML)
|
||||
@@ -101,7 +101,7 @@ export default new Vuex.Store({
|
||||
.then(data => {
|
||||
commit('setCountries', data)
|
||||
})
|
||||
.catch(() => {})
|
||||
.catch(handleError)
|
||||
.finally(() => {
|
||||
commit('endLoading')
|
||||
})
|
||||
@@ -166,6 +166,7 @@ export default new Vuex.Store({
|
||||
.then(checkStatus)
|
||||
.then(response => response.json())
|
||||
.then(response => response)
|
||||
.catch(handleError)
|
||||
.finally(() => {
|
||||
commit('endLoading')
|
||||
})
|
||||
@@ -183,6 +184,7 @@ export default new Vuex.Store({
|
||||
.then(checkStatus)
|
||||
.then(response => response.json())
|
||||
.then(data => data)
|
||||
.catch(handleError)
|
||||
.finally(() => {
|
||||
commit('endLoading')
|
||||
})
|
||||
@@ -203,12 +205,7 @@ export default new Vuex.Store({
|
||||
commit('setWatchlist', data.watchlist)
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
commit('alert', {
|
||||
message: 'Es ist ein Fehler aufgetreten :(',
|
||||
success: false,
|
||||
})
|
||||
})
|
||||
.catch(handleError)
|
||||
.finally(() => {
|
||||
commit('endLoading')
|
||||
})
|
||||
@@ -231,6 +228,7 @@ export default new Vuex.Store({
|
||||
success: true,
|
||||
})
|
||||
})
|
||||
.catch(handleError)
|
||||
.finally(() => {
|
||||
commit('endLoading')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user