mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-16 18:31:49 +01:00
Use async/await
This commit is contained in:
parent
2fc1ec4020
commit
7e53eea7f2
@ -151,29 +151,22 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
getAccount: function (id) {
|
async getAccount(id) {
|
||||||
let accountId = id
|
try {
|
||||||
|
const { data } = await axios.get('api/twofaccounts/' + id)
|
||||||
|
|
||||||
axios.get('api/twofaccounts/' + id).then(response => {
|
this.twofaccount.id = data.id
|
||||||
|
this.twofaccount.service = data.service
|
||||||
|
this.twofaccount.account = data.account
|
||||||
|
this.twofaccount.icon = data.icon
|
||||||
|
|
||||||
this.twofaccount.id = response.data.id
|
this.$refs.OneTimePassword.AccountId = data.id
|
||||||
this.twofaccount.service = response.data.service
|
|
||||||
this.twofaccount.account = response.data.account
|
|
||||||
this.twofaccount.icon = response.data.icon
|
|
||||||
|
|
||||||
this.$refs.OneTimePassword.AccountId = response.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.data.message } });
|
||||||
if (error.response.status === 404) {
|
}
|
||||||
this.$router.push({name: '404', params: { err : error.response.data.error }});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteAccount: function (id) {
|
deleteAccount: function (id) {
|
||||||
@ -188,19 +181,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
logout(evt) {
|
async logout(evt) {
|
||||||
if(confirm(this.$t('auth.confirm.logout'))) {
|
if(confirm(this.$t('auth.confirm.logout'))) {
|
||||||
axios.post('api/logout').then(response => {
|
try {
|
||||||
|
await axios.get('api/logout')
|
||||||
|
|
||||||
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.data.message } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,23 +52,28 @@
|
|||||||
validationErrors: {}
|
validationErrors: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods : {
|
methods : {
|
||||||
handleSubmit(e){
|
async handleSubmit(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
axios.post('api/login', {
|
try {
|
||||||
email: this.email,
|
const { data } = await axios.post('api/login', {
|
||||||
password: this.password
|
email: this.email,
|
||||||
})
|
password: this.password
|
||||||
.then(response => {
|
})
|
||||||
localStorage.setItem('user',response.data.message.name)
|
|
||||||
localStorage.setItem('jwt',response.data.message.token)
|
localStorage.setItem('user',data.message.name)
|
||||||
|
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 = {}
|
||||||
|
|
||||||
if( error.response.status === 401 ) {
|
if( error.response.status === 401 ) {
|
||||||
this.validationErrors['email'] = ''
|
this.validationErrors['email'] = ''
|
||||||
this.validationErrors['password'] = [ this.$t('auth.forms.password_do_not_match') ]
|
this.validationErrors['password'] = [ this.$t('auth.forms.password_do_not_match') ]
|
||||||
@ -79,9 +84,11 @@
|
|||||||
else {
|
else {
|
||||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
beforeRouteEnter (to, from, next) {
|
beforeRouteEnter (to, from, next) {
|
||||||
if (localStorage.getItem('jwt')) {
|
if (localStorage.getItem('jwt')) {
|
||||||
return next('/');
|
return next('/');
|
||||||
|
@ -73,7 +73,7 @@
|
|||||||
.then(response => {
|
.then(response => {
|
||||||
if( response.data.userCount > 0) {
|
if( response.data.userCount > 0) {
|
||||||
this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user')
|
this.errorMessage = this.$t('errors.already_one_user_registered') + ' ' + this.$t('errors.cannot_register_more_user')
|
||||||
//this.$router.push({ name: 'flooded' });
|
this.$router.push({ name: 'flooded' });
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@ -82,28 +82,35 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods : {
|
methods : {
|
||||||
handleSubmit(e) {
|
async handleSubmit(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
axios.post('api/register', {
|
try {
|
||||||
name: this.name,
|
const { data } = await axios.post('api/register', {
|
||||||
email: this.email,
|
name: this.name,
|
||||||
password: this.password,
|
email: this.email,
|
||||||
password_confirmation : this.password_confirmation
|
password: this.password,
|
||||||
})
|
password_confirmation : this.password_confirmation
|
||||||
.then(response => {
|
})
|
||||||
|
|
||||||
|
localStorage.setItem('user',data.message.name)
|
||||||
|
localStorage.setItem('jwt',data.message.token)
|
||||||
|
|
||||||
if (localStorage.getItem('jwt') != null){
|
if (localStorage.getItem('jwt') != null){
|
||||||
this.$router.go('/');
|
this.$router.push({name: 'accounts'})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
.catch(error => {
|
catch (error) {
|
||||||
|
|
||||||
|
this.validationErrors = {}
|
||||||
|
|
||||||
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.data.message } });
|
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user