A free open source IT asset/license management system
Check for setup to have completed before running the 2fa middleware. Otherwise new installs fail (#2885)
Daniel Meltzerf4fc78302636
diff --git a/app/Http/Middleware/CheckForTwoFactor.php b/app/Http/Middleware/CheckForTwoFactor.phpindex b69127e2fd..476e9fdd57 100644--- a/app/Http/Middleware/CheckForTwoFactor.php+++ b/app/Http/Middleware/CheckForTwoFactor.php@@ -1,9 +1,11 @@<?phpnamespace App\Http\Middleware;-use Closure;++use App\Models\Setting;use Auth;+use Closure;+use Illuminate\Support\Facades\Schema;use Log;-use App\Models\Setting;class CheckForTwoFactor{@@ -23,28 +25,27 @@ class CheckForTwoFactor}// Two-factor is enabled (either optional or required)- if (Auth::check() && (Setting::getSettings()->two_factor_enabled!='')) {+ if (Schema::hasTable('settings')) {+ if (Auth::check() && (Setting::getSettings()->two_factor_enabled!='')) {- // This user is already 2fa-authed- if ($request->session()->get('2fa_authed')){- return $next($request);- }+ // This user is already 2fa-authed+ if ($request->session()->get('2fa_authed')) {+ return $next($request);+ }- // Two-factor is optional and the user has NOT opted in, let them through- if ((Setting::getSettings()->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', 'Please enter your two-factor authentication code.');- }+ // Two-factor is optional and the user has NOT opted in, let them through+ if ((Setting::getSettings()->two_factor_enabled=='1') && (Auth::user()->two_factor_optin!='1')) {+ return $next($request);+ }- return redirect()->route('two-factor-enroll')->with('success', 'Please enroll a device in two-factor authentication.');-+ // 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', 'Please enter your two-factor authentication code.');+ }+ return redirect()->route('two-factor-enroll')->with('success', 'Please enroll a device in two-factor authentication.');+ }}-return $next($request);}