mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-02-16 18:31:49 +01:00
Remove unnecessary try|catch
This commit is contained in:
parent
5531c0e7e1
commit
c6b7c4e495
@ -58,12 +58,9 @@ public function store(Request $request)
|
|||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
try {
|
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
|
||||||
return response()->json($twofaccount, 200);
|
return response()->json($twofaccount, 200);
|
||||||
} catch (\Exception $e) {
|
|
||||||
return response()->json( ['message' => 'not found' ], 404);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -95,45 +92,37 @@ public function update(Request $request, $id)
|
|||||||
'service' => 'required',
|
'service' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||||
|
|
||||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
if( $twofaccount->type === 'hotp' ) {
|
||||||
|
|
||||||
if( $twofaccount->type === 'hotp' ) {
|
// HOTP can be desynchronized from the verification
|
||||||
|
// server so we let the user the possibility to force
|
||||||
|
// the counter.
|
||||||
|
|
||||||
// HOTP can be desynchronized from the verification
|
$this->validate($request, [
|
||||||
// server so we let the user the possibility to force
|
'counter' => 'required|integer',
|
||||||
// the counter.
|
|
||||||
|
|
||||||
$this->validate($request, [
|
|
||||||
'counter' => 'required|integer',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// we set an OTP object to get the its current counter
|
|
||||||
// and we update it if a new one has been submited
|
|
||||||
$otp = OTP::get($twofaccount->uri);
|
|
||||||
|
|
||||||
if( $otp->getCounter() !== $request->counter ) {
|
|
||||||
$otp->setParameter( 'counter', $request->counter );
|
|
||||||
$twofaccount->uri = $otp->getProvisioningUri();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$twofaccount->update([
|
|
||||||
'service' => $request->service,
|
|
||||||
'account' => $request->account,
|
|
||||||
'icon' => $request->icon,
|
|
||||||
'uri' => $twofaccount->uri,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json($twofaccount, 200);
|
// we set an OTP object to get the its current counter
|
||||||
|
// and we update it if a new one has been submited
|
||||||
|
$otp = OTP::get($twofaccount->uri);
|
||||||
|
|
||||||
|
if( $otp->getCounter() !== $request->counter ) {
|
||||||
|
$otp->setParameter( 'counter', $request->counter );
|
||||||
|
$twofaccount->uri = $otp->getProvisioningUri();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (\Exception $e) {
|
|
||||||
|
|
||||||
return response()->json( ['message' => 'not found' ] , 404);
|
$twofaccount->update([
|
||||||
|
'service' => $request->service,
|
||||||
|
'account' => $request->account,
|
||||||
|
'icon' => $request->icon,
|
||||||
|
'uri' => $twofaccount->uri,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json($twofaccount, 200);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,27 +134,20 @@ public function update(Request $request, $id)
|
|||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
|
|
||||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||||
|
|
||||||
// delete icon
|
// delete icon
|
||||||
$storedIcon = 'public/icons/' . $twofaccount->icon;
|
$storedIcon = 'public/icons/' . $twofaccount->icon;
|
||||||
|
|
||||||
if( Storage::exists($storedIcon) ) {
|
|
||||||
Storage::delete($storedIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
$twofaccount->delete();
|
|
||||||
|
|
||||||
return response()->json(null, 204);
|
|
||||||
|
|
||||||
|
if( Storage::exists($storedIcon) ) {
|
||||||
|
Storage::delete($storedIcon);
|
||||||
}
|
}
|
||||||
catch (\Exception $e) {
|
|
||||||
|
|
||||||
return response()->json(['message' => 'already gone'], 404);
|
// delete account
|
||||||
|
$twofaccount->delete();
|
||||||
|
|
||||||
}
|
return response()->json(null, 204);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user