-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from thedevdojo/tnylea/add-two-factor-auth-cont…
…roller Add TwoFactorAuthenticationController with code confirmation methods
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Http/Controllers/TwoFactorAuthenticationController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Devdojo\Auth\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use PragmaRX\Google2FA\Google2FA; | ||
use App\Models\User; | ||
|
||
class TwoFactorAuthenticationController extends Controller | ||
{ | ||
protected $google2fa; | ||
|
||
public function __construct(Google2FA $google2fa) | ||
{ | ||
$this->google2fa = $google2fa; | ||
} | ||
|
||
public function confirmAuthenticationCode(Request $request) | ||
{ | ||
$user = $request->user(); | ||
$valid = $this->google2fa->verifyKey($user->two_factor_secret, $request->code); | ||
|
||
if ($valid) { | ||
// Handle successful authentication | ||
} else { | ||
// Handle failed authentication | ||
} | ||
} | ||
|
||
public function confirmRecoveryCode(Request $request) | ||
{ | ||
$user = $request->user(); | ||
$recoveryCodes = $user->two_factor_recovery_codes; | ||
$valid = in_array($request->code, $recoveryCodes); | ||
|
||
if ($valid) { | ||
// Handle successful recovery code confirmation | ||
} else { | ||
// Handle failed recovery code confirmation | ||
} | ||
} | ||
} |