X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a3ead5062acc169ae3486d90ac2befe3db86bfe6..refs/pull/3728/head:/app/Http/Controllers/Auth/LoginController.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 742e10472..1d6a36c5b 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -24,18 +24,18 @@ class LoginController extends Controller | to conveniently provide its functionality to your applications. | */ - - use AuthenticatesUsers; + use AuthenticatesUsers { + logout as traitLogout; + } /** * Redirection paths. */ protected $redirectTo = '/'; protected $redirectPath = '/'; - protected $redirectAfterLogout = '/login'; - protected $socialAuthService; - protected $loginService; + protected SocialAuthService $socialAuthService; + protected LoginService $loginService; /** * Create a new controller instance. @@ -50,7 +50,6 @@ class LoginController extends Controller $this->loginService = $loginService; $this->redirectPath = url('/'); - $this->redirectAfterLogout = url('/https/source.bookstackapp.com/login'); } public function username() @@ -73,6 +72,7 @@ class LoginController extends Controller { $socialDrivers = $this->socialAuthService->getActiveDrivers(); $authMethod = config('auth.method'); + $preventInitiation = $request->get('prevent_auto_init') === 'true'; if ($request->has('email')) { session()->flashInput([ @@ -84,6 +84,12 @@ class LoginController extends Controller // Store the previous location for redirect after login $this->updateIntendedFromPrevious(); + if (!$preventInitiation && $this->shouldAutoInitiate()) { + return view('auth.login-initiate', [ + 'authMethod' => $authMethod, + ]); + } + return view('auth.login', [ 'socialDrivers' => $socialDrivers, 'authMethod' => $authMethod, @@ -107,8 +113,10 @@ class LoginController extends Controller // If the class is using the ThrottlesLogins trait, we can automatically throttle // the login attempts for this application. We'll key this by the username and // the IP address of the client making these requests into this application. - if (method_exists($this, 'hasTooManyLoginAttempts') && - $this->hasTooManyLoginAttempts($request)) { + if ( + method_exists($this, 'hasTooManyLoginAttempts') && + $this->hasTooManyLoginAttempts($request) + ) { $this->fireLockoutEvent($request); Activity::logFailedLogin($username); @@ -251,4 +259,32 @@ class LoginController extends Controller redirect()->setIntendedUrl($previous); } + + /** + * Check if login auto-initiate should be valid based upon authentication config. + */ + protected function shouldAutoInitiate(): bool + { + $socialDrivers = $this->socialAuthService->getActiveDrivers(); + $authMethod = config('auth.method'); + $autoRedirect = config('auth.auto_initiate'); + + return $autoRedirect && count($socialDrivers) === 0 && in_array($authMethod, ['oidc', 'saml2']); + } + + /** + * Logout user and perform subsequent redirect. + * + * @param \Illuminate\Http\Request $request + * + * @return mixed + */ + public function logout(Request $request) + { + $this->traitLogout($request); + + $redirectUri = $this->shouldAutoInitiate() ? '/login?prevent_auto_init=true' : '/'; + + return redirect($redirectUri); + } }