Remove async/await

This commit is contained in:
Bubka 2020-01-19 22:29:36 +01:00
parent 3e1007b8fb
commit 8e4f8c4f8a
7 changed files with 115 additions and 111 deletions

View File

@ -151,10 +151,10 @@
}, },
methods: { methods: {
async getAccount(id) { getAccount(id) {
try {
const { data } = await axios.get('api/twofaccounts/' + id)
axios.get('api/twofaccounts/' + id)
.then(response => {
this.twofaccount.id = data.id this.twofaccount.id = data.id
this.twofaccount.service = data.service this.twofaccount.service = data.service
this.twofaccount.account = data.account this.twofaccount.account = data.account
@ -163,10 +163,11 @@
this.$refs.OneTimePassword.AccountId = data.id this.$refs.OneTimePassword.AccountId = data.id
this.$refs.OneTimePassword.getOTP() this.$refs.OneTimePassword.getOTP()
this.ShowTwofaccountInModal = true; this.ShowTwofaccountInModal = true;
} })
catch (error) { .catch(error => {
//this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} });
}, },
deleteAccount: function (id) { deleteAccount: function (id) {
@ -175,27 +176,27 @@
axios.delete('/api/twofaccounts/' + id) axios.delete('/api/twofaccounts/' + id)
this.accounts.splice(this.accounts.findIndex(x => x.id === id), 1); this.accounts.splice(this.accounts.findIndex(x => x.id === id), 1);
this.showAccounts = this.accounts.length > 0 ? true : false this.showAccounts = this.accounts.length > 0 ? true : false
this.showNoAccount = !this.showAccounts this.showNoAccount = !this.showAccounts
} }
}, },
async logout(evt) { logout(evt) {
if(confirm(this.$t('auth.confirm.logout'))) { if(confirm(this.$t('auth.confirm.logout'))) {
try {
await axios.get('api/logout')
axios.get('api/logout')
.then(response => {
localStorage.removeItem('jwt'); localStorage.removeItem('jwt');
localStorage.removeItem('user'); localStorage.removeItem('user');
delete axios.defaults.headers.common['Authorization']; delete axios.defaults.headers.common['Authorization'];
this.$router.go('/login'); this.$router.go('/login');
} })
catch (error) { .catch(error => {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} });
} }
} }

View File

@ -60,23 +60,22 @@
}, },
methods : { methods : {
async handleSubmit(e) { handleSubmit(e) {
e.preventDefault() e.preventDefault()
try { axios.post('api/login', {
const { data } = await axios.post('api/login', { email: this.email,
email: this.email, password: this.password
password: this.password })
}) .then(response => {
localStorage.setItem('user',response.data.message.name)
localStorage.setItem('user',data.message.name) localStorage.setItem('jwt',response.data.message.token)
localStorage.setItem('jwt',data.message.token)
if (localStorage.getItem('jwt') != null){ if (localStorage.getItem('jwt') != null){
this.$router.go('/'); this.$router.go('/');
} }
} })
catch (error) { .catch(error => {
this.validationErrors = {} this.validationErrors = {}
this.errorMessage = '' this.errorMessage = ''
@ -90,7 +89,7 @@
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }
} });
} }
}, },

View File

@ -82,25 +82,25 @@
}, },
methods : { methods : {
async handleSubmit(e) { handleSubmit(e) {
e.preventDefault() e.preventDefault()
try { axios.post('api/register', {
const { data } = await axios.post('api/register', { name: this.name,
name: this.name, email: this.email,
email: this.email, password: this.password,
password: this.password, password_confirmation : this.password_confirmation
password_confirmation : this.password_confirmation })
}) .then(response => {
localStorage.setItem('user',data.message.name) localStorage.setItem('user',response.data.message.name)
localStorage.setItem('jwt',data.message.token) localStorage.setItem('jwt',response.data.message.token)
if (localStorage.getItem('jwt') != null){ if (localStorage.getItem('jwt') != null){
this.$router.push({name: 'accounts'}) this.$router.push({name: 'accounts'})
} }
} })
catch (error) { .catch(error => {
this.validationErrors = {} this.validationErrors = {}
@ -110,7 +110,7 @@
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }
} });
} }
}, },

View File

@ -46,19 +46,21 @@
} }
}, },
methods : { methods : {
async handleSubmit(e){ handleSubmit(e){
e.preventDefault() e.preventDefault()
this.validationErrors = {} this.validationErrors = {}
try { axios.post('/api/password/email', {
const { data } = await axios.post('/api/password/email', { email: this.email
email: this.email })
}) .then(response => {
this.response = response.data.status
})
.catch(error => {
this.response = data.status
}
catch (error) {
if( error.response.data.errors ) { if( error.response.data.errors ) {
this.validationErrors = error.response.data.errors this.validationErrors = error.response.data.errors
} }
@ -68,7 +70,9 @@
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }
}
});
} }
} }
} }

View File

@ -62,22 +62,24 @@
}, },
methods : { methods : {
async handleSubmit(e) { handleSubmit(e) {
e.preventDefault() e.preventDefault()
this.validationErrors = {} this.validationErrors = {}
try { axios.post('/api/password/reset', {
const { data } = await axios.post('/api/password/reset', { email: this.email,
email: this.email, password: this.password,
password: this.password, password_confirmation : this.password_confirmation,
password_confirmation : this.password_confirmation, token: this.token
token: this.token })
}) .then(response => {
this.$router.go('/'); this.$router.go('/');
}
catch (error) { })
.catch(error => {
if( error.response.data.errors ) { if( error.response.data.errors ) {
this.validationErrors = error.response.data.errors this.validationErrors = error.response.data.errors
} }
@ -87,7 +89,8 @@
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }
}
});
} }
}, },
} }

View File

@ -106,23 +106,22 @@
methods: { methods: {
async createAccount() { createAccount() {
// set current temp icon as account icon // set current temp icon as account icon
this.twofaccount.icon = this.tempIcon this.twofaccount.icon = this.tempIcon
try { axios.post('/api/twofaccounts', this.twofaccount)
await axios.post('/api/twofaccounts', this.twofaccount) .then(response => {
this.$router.push({name: 'accounts', params: { InitialEditMode: false }}); this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
} })
catch (error) { .catch(error => {
if( error.response.data.validation ) { if( error.response.data.validation ) {
this.validationErrors = error.response.data.validation this.validationErrors = error.response.data.validation
} }
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
} }
} });
}, },
@ -135,7 +134,7 @@
this.$router.push({name: 'accounts', params: { InitialEditMode: false }}); this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
}, },
async uploadQrcode(event) { uploadQrcode(event) {
let imgdata = new FormData(); let imgdata = new FormData();
@ -147,24 +146,23 @@
} }
} }
try { axios.post('/api/qrcode/decode', imgdata, config)
const { data } = await axios.post('/api/qrcode/decode', imgdata, config) .then(response => {
this.twofaccount = response.data;
this.twofaccount = data;
this.validationErrors['qrcode'] = ''; this.validationErrors['qrcode'] = '';
} })
catch (error) { .catch(error => {
if( error.response.data.validation ) { if( error.response.data.validation ) {
this.validationErrors = error.response.data.validation this.validationErrors = error.response.data.validation
} }
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
} }
} });
}, },
async uploadIcon(event) { uploadIcon(event) {
// clean possible already uploaded temp icon // clean possible already uploaded temp icon
if( this.tempIcon ) { if( this.tempIcon ) {
@ -181,27 +179,26 @@
} }
} }
try { axios.post('/api/icon/upload', imgdata, config)
const { data } = await axios.post('/api/icon/upload', imgdata, config) .then(response => {
this.tempIcon = response.data;
this.tempIcon = data;
this.validationErrors['icon'] = ''; this.validationErrors['icon'] = '';
} })
catch (error) { .catch(error => {
if( error.response.data.validation ) { if( error.response.data.validation ) {
this.validationErrors = error.response.data.validation this.validationErrors = error.response.data.validation
} }
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
} }
} });
}, },
async deleteIcon(event) { deleteIcon(event) {
if(this.tempIcon) { if(this.tempIcon) {
await axios.delete('/api/icon/delete/' + this.tempIcon) axios.delete('/api/icon/delete/' + this.tempIcon)
this.tempIcon = '' this.tempIcon = ''
} }
}, },

View File

@ -72,22 +72,23 @@
}, },
methods: { methods: {
async getAccount () { getAccount () {
try {
const { data } = await axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
this.twofaccount = data axios.get('/api/twofaccounts/' + this.$route.params.twofaccountId)
.then(response => {
this.twofaccount = response.data
this.twofaccountExists = true this.twofaccountExists = true
// set account icon as temp icon // set account icon as temp icon
this.tempIcon = this.twofaccount.icon this.tempIcon = this.twofaccount.icon
} })
catch (error) { .catch(error => {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} });
}, },
async updateAccount() { updateAccount() {
// Set new icon and delete old one // Set new icon and delete old one
if( this.tempIcon !== this.twofaccount.icon ) { if( this.tempIcon !== this.twofaccount.icon ) {
@ -100,19 +101,19 @@
this.deleteIcon() this.deleteIcon()
} }
try { axios.put('/api/twofaccounts/' + this.$route.params.twofaccountId, this.twofaccount)
await axios.put('/api/twofaccounts/' + this.$route.params.twofaccountId, this.twofaccount) .then(response => {
this.$router.push({name: 'accounts', params: { InitialEditMode: true }}); this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
} })
catch (error) { .catch(error => {
if( error.response.data.validation ) { if( error.response.data.validation ) {
this.validationErrors = error.response.data.validation this.validationErrors = error.response.data.validation
} }
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }
} });
}, },
cancelCreation: function() { cancelCreation: function() {
@ -122,7 +123,7 @@
this.$router.push({name: 'accounts', params: { InitialEditMode: true }}); this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
}, },
async uploadIcon(event) { uploadIcon(event) {
// clean possible tempIcon but keep original one // clean possible tempIcon but keep original one
this.deleteIcon() this.deleteIcon()
@ -137,27 +138,26 @@
} }
} }
try { axios.post('/api/icon/upload', imgdata, config)
const { data } = await axios.post('/api/icon/upload', imgdata, config) .then(response => {
this.tempIcon = response.data;
this.tempIcon = data;
this.validationErrors['icon'] = ''; this.validationErrors['icon'] = '';
} })
catch (error) { .catch(error => {
if( error.response.data.validation ) { if( error.response.data.validation ) {
this.validationErrors = error.response.data.validation this.validationErrors = error.response.data.validation
} }
else { else {
this.$router.push({ name: 'genericError', params: { err: error.response } }); this.$router.push({ name: 'genericError', params: { err: error.response } });
} }
} });
}, },
async deleteIcon(event) { deleteIcon(event) {
if( this.tempIcon && this.tempIcon !== this.twofaccount.icon ) { if( this.tempIcon && this.tempIcon !== this.twofaccount.icon ) {
await axios.delete('/api/icon/delete/' + this.tempIcon) axios.delete('/api/icon/delete/' + this.tempIcon)
} }
this.tempIcon = '' this.tempIcon = ''