mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-16 18:31:49 +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',
|
'service' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
// Here we catch a possible missing model exception in order to
|
||||||
|
// delete orphan submited icon
|
||||||
|
try {
|
||||||
|
|
||||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
$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' ) {
|
if( $twofaccount->type === 'hotp' ) {
|
||||||
|
|
||||||
// HOTP can be desynchronized from the verification
|
// HOTP can be desynchronized from the verification
|
||||||
@ -138,11 +153,7 @@ public function destroy($id)
|
|||||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||||
|
|
||||||
// delete icon
|
// delete icon
|
||||||
$storedIcon = 'public/icons/' . $twofaccount->icon;
|
Storage::delete('public/icons/' . $twofaccount->icon);
|
||||||
|
|
||||||
if( Storage::exists($storedIcon) ) {
|
|
||||||
Storage::delete($storedIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete account
|
// delete account
|
||||||
$twofaccount->delete();
|
$twofaccount->delete();
|
||||||
|
Loading…
Reference in New Issue
Block a user