3 namespace BookStack\Http\Middleware;
5 use BookStack\Auth\Access\LoginService;
6 use BookStack\Auth\Access\Mfa\MfaSession;
9 class AuthenticatedOrPendingMfa
12 protected $loginService;
13 protected $mfaSession;
15 public function __construct(LoginService $loginService, MfaSession $mfaSession)
17 $this->loginService = $loginService;
18 $this->mfaSession = $mfaSession;
23 * Handle an incoming request.
25 * @param \Illuminate\Http\Request $request
26 * @param \Closure $next
29 public function handle($request, Closure $next)
31 $user = auth()->user();
32 $loggedIn = $user !== null;
33 $lastAttemptUser = $this->loginService->getLastLoginAttemptUser();
35 if ($loggedIn || ($lastAttemptUser && $this->mfaSession->isPendingMfaSetup($lastAttemptUser))) {
36 return $next($request);
39 return redirect()->to(url('/login'));