mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-22 16:23:18 +01:00
Delete possible orphan icon when updating a twofaccount
This commit is contained in:
parent
52ac639940
commit
59fe66710a
@ -92,8 +92,23 @@ public function update(Request $request, $id)
|
||||
'service' => 'required',
|
||||
]);
|
||||
|
||||
|
||||
// Here we catch a possible missing model exception in order to
|
||||
// delete orphan submited icon
|
||||
try {
|
||||
|
||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||
|
||||
} catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) {
|
||||
|
||||
if( $request->icon ) {
|
||||
Storage::delete('public/icons/' . $request->icon);
|
||||
}
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
|
||||
if( $twofaccount->type === 'hotp' ) {
|
||||
|
||||
// HOTP can be desynchronized from the verification
|
||||
@ -138,11 +153,7 @@ public function destroy($id)
|
||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||
|
||||
// delete icon
|
||||
$storedIcon = 'public/icons/' . $twofaccount->icon;
|
||||
|
||||
if( Storage::exists($storedIcon) ) {
|
||||
Storage::delete($storedIcon);
|
||||
}
|
||||
Storage::delete('public/icons/' . $twofaccount->icon);
|
||||
|
||||
// delete account
|
||||
$twofaccount->delete();
|
||||
|
Loading…
Reference in New Issue
Block a user