Skip to content

Commit

Permalink
Use existing method to handle the login
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed May 22, 2022
1 parent 4d3362b commit 3ae70ef
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,21 @@ public function login(Request $request): JsonResponse
$this->sendFailedLoginResponse($request, $user);
}

if ($user->use_totp) {
$token = Str::random(64);

$request->session()->put('auth_confirmation_token', [
'user_id' => $user->id,
'token_value' => $token,
'expires_at' => CarbonImmutable::now()->addMinutes(5),
]);

return new JsonResponse([
'data' => [
'complete' => false,
'confirmation_token' => $token,
],
]);
if (!$user->use_totp) {
return $this->sendLoginResponse($user, $request);
}

$this->auth->guard()->login($user, true);

$request->session()->regenerate();

return $this->sendLoginResponse($user, $request);
$request->session()->put('auth_confirmation_token', [
'user_id' => $user->id,
'token_value' => $token = Str::random(64),
'expires_at' => CarbonImmutable::now()->addMinutes(5),
]);

return new JsonResponse([
'data' => [
'complete' => false,
'confirmation_token' => $token,
],
]);
}
}

0 comments on commit 3ae70ef

Please sign in to comment.