Skip to content

Commit 31cc0d9

Browse files
committed
cleaning up the 2fa controller
1 parent bda39b3 commit 31cc0d9

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

app/Http/Controllers/Settings/TwoFactorAuthController.php

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function show(Request $request)
3434

3535
return Inertia::render('settings/two-factor', [
3636
'confirmed' => $confirmed,
37-
'recoveryCodes' => $this->getRecoveryCodes($user),
37+
'recoveryCodes' => !is_null($user->two_factor_secret) ? json_decode(decrypt($user->two_factor_recovery_codes)) : [],
3838
]);
3939
}
4040

@@ -132,39 +132,4 @@ public function disable(Request $request)
132132
$disableTwoFactorAuthentication = app(DisableTwoFactorAuthentication::class);
133133
$disableTwoFactorAuthentication($request->user());
134134
}
135-
136-
/**
137-
* Get the recovery codes for the user.
138-
*
139-
* @param \Illuminate\Http\Request $request
140-
* @return \Illuminate\Http\Response
141-
*/
142-
public function recoveryCodes(Request $request)
143-
{
144-
if (!$this->twoFactorEnabled($request->user())) {
145-
return response('', 404);
146-
}
147-
148-
return response()->json([
149-
'recoveryCodes' => $this->getRecoveryCodes($request->user()),
150-
]);
151-
}
152-
153-
/**
154-
* Helper to check if 2FA is enabled for a user.
155-
*/
156-
private function twoFactorEnabled($user)
157-
{
158-
return !is_null($user->two_factor_secret);
159-
}
160-
161-
/**
162-
* Helper to get recovery codes for a user, or empty array if not enabled.
163-
*/
164-
private function getRecoveryCodes($user)
165-
{
166-
return $this->twoFactorEnabled($user)
167-
? json_decode(decrypt($user->two_factor_recovery_codes))
168-
: [];
169-
}
170135
}

0 commit comments

Comments
 (0)