Skip to content

Commit

Permalink
adjust redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 5, 2021
1 parent 04ab43c commit 67d7743
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Fortify\Http\Controllers;

use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Routing\Controller;
use Laravel\Fortify\Contracts\FailedTwoFactorLoginResponse;
use Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse;
Expand Down Expand Up @@ -33,12 +34,12 @@ public function __construct(StatefulGuard $guard)
* Show the two factor authentication challenge view.
*
* @param \Laravel\Fortify\Http\Requests\TwoFactorLoginRequest $request
* @return \Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse|\Illuminate\Http\RedirectResponse
* @return \Laravel\Fortify\Contracts\TwoFactorChallengeViewResponse
*/
public function create(TwoFactorLoginRequest $request)
public function create(TwoFactorLoginRequest $request): TwoFactorChallengeViewResponse
{
if (! $request->hasChallengedUser()) {
return redirect()->route('login');
throw new HttpResponseException(redirect()->route('login'));
}

return app(TwoFactorChallengeViewResponse::class);
Expand Down
32 changes: 16 additions & 16 deletions src/Http/Requests/TwoFactorLoginRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ public function validRecoveryCode()
});
}

/**
* Determine if there is a challenged user in the current session.
*
* @return bool
*/
public function hasChallengedUser()
{
try {
$user = $this->challengedUser();
} catch (HttpResponseException $e) {
return false;
}

return $user !== null;
}

/**
* Get the user that is attempting the two factor challenge.
*
Expand All @@ -98,22 +114,6 @@ public function challengedUser()
return $this->challengedUser = $user;
}

/**
* Determine if there's a challenged user in the current session.
*
* @return bool
*/
public function hasChallengedUser()
{
try {
$user = $this->challengedUser();
} catch (HttpResponseException $e) {
return false;
}

return $user !== null;
}

/**
* Determine if the user wanted to be remembered after login.
*
Expand Down

0 comments on commit 67d7743

Please sign in to comment.