mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-08-14 07:48:37 +02:00
Better errors handling for TwoFAccount controller
This commit is contained in:
@ -17,20 +17,20 @@
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help is-danger help-for-file" v-if="errors.qrcode">{{ errors.qrcode.toString() }}</p>
|
||||
<p class="help is-danger help-for-file" v-if="validationErrors.qrcode">{{ validationErrors.qrcode.toString() }}</p>
|
||||
<div class="field">
|
||||
<label class="label">{{ $t('twofaccounts.service') }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="twofaccount.service" autofocus />
|
||||
</div>
|
||||
<p class="help is-danger" v-if="errors.service">{{ errors.service.toString() }}</p>
|
||||
<p class="help is-danger" v-if="validationErrors.service">{{ validationErrors.service.toString() }}</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="twofaccount.account" />
|
||||
</div>
|
||||
<p class="help is-danger" v-if="errors.account">{{ errors.account.toString() }}</p>
|
||||
<p class="help is-danger" v-if="validationErrors.account">{{ validationErrors.account.toString() }}</p>
|
||||
</div>
|
||||
<div class="field" style="margin-bottom: 0.5rem;">
|
||||
<label class="label">{{ $t('twofaccounts.forms.totp_uri') }}</label>
|
||||
@ -54,7 +54,7 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help is-danger help-for-file" v-if="errors.uri">{{ errors.uri.toString() }}</p>
|
||||
<p class="help is-danger help-for-file" v-if="validationErrors.uri">{{ validationErrors.uri.toString() }}</p>
|
||||
<div class="field">
|
||||
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
||||
<div class="file is-dark">
|
||||
@ -73,7 +73,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help is-danger help-for-file" v-if="errors.icon">{{ errors.icon.toString() }}</p>
|
||||
<p class="help is-danger help-for-file" v-if="validationErrors.icon">{{ validationErrors.icon.toString() }}</p>
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-link">{{ $t('twofaccounts.forms.create') }}</button>
|
||||
@ -100,7 +100,7 @@
|
||||
},
|
||||
uriIsLocked: true,
|
||||
tempIcon: '',
|
||||
errors: {}
|
||||
validationErrors: {}
|
||||
}
|
||||
},
|
||||
|
||||
@ -121,8 +121,11 @@
|
||||
this.$router.push({name: 'accounts', params: { InitialEditMode: false }});
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response.status === 400) {
|
||||
this.errors = error.response.data.error
|
||||
if( error.response.data.validation ) {
|
||||
this.validationErrors = error.response.data.validation
|
||||
}
|
||||
else {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -156,13 +159,16 @@
|
||||
axios.post('/api/qrcode/decode', imgdata, config)
|
||||
.then(response => {
|
||||
this.twofaccount = response.data;
|
||||
this.errors['qrcode'] = '';
|
||||
this.validationErrors['qrcode'] = '';
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response.status === 400) {
|
||||
this.errors = error.response.data.error
|
||||
if( error.response.data.validation ) {
|
||||
this.validationErrors = error.response.data.validation
|
||||
this.clearTwofaccount()
|
||||
}
|
||||
else {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@ -192,11 +198,14 @@
|
||||
.then(response => {
|
||||
console.log('icon path > ', response);
|
||||
this.tempIcon = response.data;
|
||||
this.errors['icon'] = '';
|
||||
this.validationErrors['icon'] = '';
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response.status === 400) {
|
||||
this.errors = error.response.data.error
|
||||
if( error.response.data.validation ) {
|
||||
this.validationErrors = error.response.data.validation
|
||||
}
|
||||
else {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -9,14 +9,14 @@
|
||||
<div class="control">
|
||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.service.placeholder')" v-model="twofaccount.service" autofocus />
|
||||
</div>
|
||||
<p class="help is-danger" v-if="errors.service">{{ errors.service.toString() }}</p>
|
||||
<p class="help is-danger" v-if="validationErrors.service">{{ validationErrors.service.toString() }}</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ $t('twofaccounts.account') }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" :placeholder="$t('twofaccounts.forms.account.placeholder')" v-model="twofaccount.account" />
|
||||
</div>
|
||||
<p class="help is-danger" v-if="errors.account">{{ errors.account.toString() }}</p>
|
||||
<p class="help is-danger" v-if="validationErrors.account">{{ validationErrors.account.toString() }}</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label class="label">{{ $t('twofaccounts.icon') }}</label>
|
||||
@ -36,7 +36,7 @@
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help is-danger help-for-file" v-if="errors.icon">{{ errors.icon.toString() }}</p>
|
||||
<p class="help is-danger help-for-file" v-if="validationErrors.icon">{{ validationErrors.icon.toString() }}</p>
|
||||
<div class="field is-grouped">
|
||||
<div class="control">
|
||||
<button type="submit" class="button is-link">{{ $t('twofaccounts.forms.save') }}</button>
|
||||
@ -63,7 +63,7 @@
|
||||
},
|
||||
twofaccountExists: false,
|
||||
tempIcon: '',
|
||||
errors: {}
|
||||
validationErrors: {}
|
||||
}
|
||||
},
|
||||
|
||||
@ -86,9 +86,12 @@
|
||||
this.tempIcon = this.twofaccount.icon
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response.status === 404) {
|
||||
if( error.response.status === 404 ) {
|
||||
this.$router.push({ name: '404' });
|
||||
}
|
||||
else {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@ -116,12 +119,15 @@
|
||||
this.$router.push({name: 'accounts', params: { InitialEditMode: true }});
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response.status === 400) {
|
||||
this.errors = error.response.data.error
|
||||
}
|
||||
else if (error.response.status === 404) {
|
||||
if (error.response.status === 404) {
|
||||
this.$router.push({ name: '404' });
|
||||
}
|
||||
else if( error.response.data.validation ) {
|
||||
this.validationErrors = error.response.data.validation
|
||||
}
|
||||
else {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@ -160,11 +166,14 @@
|
||||
.then(response => {
|
||||
console.log('icon path > ', response);
|
||||
this.tempIcon = response.data;
|
||||
this.errors['icon'] = '';
|
||||
this.validationErrors['icon'] = '';
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.response.status === 400) {
|
||||
this.errors = error.response.data.error
|
||||
if( error.response.data.validation ) {
|
||||
this.validationErrors = error.response.data.validation
|
||||
}
|
||||
else {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
Reference in New Issue
Block a user