Better bad QR code handling in create form

This commit is contained in:
Bubka 2020-01-09 20:33:31 +01:00
parent 102d98863b
commit 543f6b89db
2 changed files with 20 additions and 18 deletions

View File

@ -42,22 +42,12 @@ public function decode(Request $request)
// delete uploaded file
Storage::delete($path);
if( empty($uri) ) {
return response()->json([
'error' => [
'qrcode' => 'Nothing readable in this QR code 😕'
]
], 400);
}
// Check uri validity
if( !TimedTOTP::get($uri) ) {
return response()->json([
'error' => [
'uri' => 'This uri do not return any TOTP code 😕'
'qrcode' => 'No valid TOTP resource in this QR code'
]
], 400);

View File

@ -161,6 +161,7 @@
.catch(error => {
if (error.response.status === 400) {
this.errors = error.response.data.error
this.clearTwofaccount()
}
});
},
@ -203,15 +204,26 @@
deleteIcon(event) {
let token = localStorage.getItem('jwt')
if(this.tempIcon) {
let token = localStorage.getItem('jwt')
axios.defaults.headers.common['Content-Type'] = 'application/json'
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
axios.defaults.headers.common['Content-Type'] = 'application/json'
axios.defaults.headers.common['Authorization'] = 'Bearer ' + token
axios.delete('/api/icon/delete/' + this.tempIcon).then(response => {
this.tempIcon = ''
}
)
axios.delete('/api/icon/delete/' + this.tempIcon).then(response => {
this.tempIcon = ''
}
)
}
},
clearTwofaccount() {
this.twofaccount.service = ''
this.twofaccount.account = ''
this.twofaccount.uri = ''
this.twofaccount.icon = ''
this.deleteIcon()
}
},