Skip to content

Commit

Permalink
implemented resend code
Browse files Browse the repository at this point in the history
  • Loading branch information
TemuulenBM committed Jan 10, 2024
1 parent f330ebe commit 2c32ef9
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Support/TwoFactorAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ public static function verifyCode(Request $request): ?string
$token = $request->input('token');
$identity = $request->input('identity');
$clientToken = $request->input('clientToken');
$newClientSessionToken = $request->input('newClientSessionToken');
$verificationCode = $request->input('verificationCode');

$user = User::where(function ($query) use ($identity) {
$query->where('email', $identity)->orWhere('phone', $identity);
Expand Down Expand Up @@ -268,6 +270,27 @@ public static function verifyCode(Request $request): ?string
$ip = $request->ip();
$token = $user->createToken($ip);

return $token->plainTextToken;
}
}
}
} elseif ($newClientSessionToken) {
$newClientSessionTokenDecoded = base64_decode($newClientSessionToken);
$newClientSessionTokenParts = explode('|', $newClientSessionTokenDecoded);
$newVerificationCodeId = $newClientSessionTokenParts[1];

if ($newVerificationCodeId) {
$newVerificationCode = VerificationCode::where('uuid', $newVerificationCodeId)->first();

if ($newVerificationCode) {
$newVerificationCodeMatches = $newVerificationCode->code === $userInputCode;

if ($newVerificationCodeMatches) {
Cache::forget($twoFaSessionKey);

$ip = $request->ip();
$token = $user->createToken($ip);

return $token->plainTextToken;
}
}
Expand Down

0 comments on commit 2c32ef9

Please sign in to comment.