route()->getName(), self::IGNORE_ROUTES) || in_array($request->route()->uri(), self::IGNORE_ROUTES)) { return $next($request); } // Two-factor is enabled (either optional or required) if ($settings = Setting::getSettings()) { if (Auth::check() && ($settings->two_factor_enabled != '')) { // This user is already 2fa-authed if ($request->session()->get('2fa_authed')==auth()->id()) { return $next($request); } // Two-factor is optional and the user has NOT opted in, let them through if (($settings->two_factor_enabled == '1') && (auth()->user()->two_factor_optin != '1')) { return $next($request); } // Otherwise make sure they're enrolled and show them the 2FA code screen if ((auth()->user()->two_factor_secret != '') && (auth()->user()->two_factor_enrolled == '1')) { return redirect()->route('two-factor')->with('info', trans('auth/message.two_factor.enter_two_factor_code')); } return redirect()->route('two-factor-enroll')->with('success', trans('auth/message.two_factor.please_enroll')); } } return $next($request); } }