X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/62342433f41f2eaef19c5e85f5ce960297ee8206..refs/pull/1630/head:/app/Http/Controllers/Auth/LoginController.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 106b90524..c739fd9a3 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -2,10 +2,11 @@ namespace BookStack\Http\Controllers\Auth; +use BookStack\Auth\Access\LdapService; +use BookStack\Auth\Access\SocialAuthService; +use BookStack\Auth\UserRepo; use BookStack\Exceptions\AuthException; use BookStack\Http\Controllers\Controller; -use BookStack\Repos\UserRepo; -use BookStack\Services\SocialAuthService; use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Foundation\Auth\AuthenticatesUsers; use Illuminate\Http\Request; @@ -36,21 +37,24 @@ class LoginController extends Controller protected $redirectAfterLogout = '/login'; protected $socialAuthService; + protected $ldapService; protected $userRepo; /** * Create a new controller instance. * - * @param SocialAuthService $socialAuthService - * @param UserRepo $userRepo + * @param \BookStack\Auth\\BookStack\Auth\Access\SocialAuthService $socialAuthService + * @param LdapService $ldapService + * @param \BookStack\Auth\UserRepo $userRepo */ - public function __construct(SocialAuthService $socialAuthService, UserRepo $userRepo) + public function __construct(SocialAuthService $socialAuthService, LdapService $ldapService, UserRepo $userRepo) { $this->middleware('guest', ['only' => ['getLogin', 'postLogin']]); $this->socialAuthService = $socialAuthService; + $this->ldapService = $ldapService; $this->userRepo = $userRepo; - $this->redirectPath = baseUrl('/'); - $this->redirectAfterLogout = baseUrl('/login'); + $this->redirectPath = url('/'); + $this->redirectAfterLogout = url('/https/source.bookstackapp.com/login'); parent::__construct(); } @@ -66,6 +70,7 @@ class LoginController extends Controller * @param Authenticatable $user * @return \Illuminate\Http\RedirectResponse * @throws AuthException + * @throws \BookStack\Exceptions\LdapException */ protected function authenticated(Request $request, Authenticatable $user) { @@ -96,9 +101,12 @@ class LoginController extends Controller auth()->login($user); } - $path = session()->pull('url.intended', '/'); - $path = baseUrl($path, true); - return redirect($path); + // Sync LDAP groups if required + if ($this->ldapService->shouldSyncGroups()) { + $this->ldapService->syncGroups($user, $request->get($this->username())); + } + + return redirect()->intended('/'); } /** @@ -118,13 +126,14 @@ class LoginController extends Controller ]); } - return view('auth/login', ['socialDrivers' => $socialDrivers, 'authMethod' => $authMethod]); + return view('auth.login', ['socialDrivers' => $socialDrivers, 'authMethod' => $authMethod]); } /** * Redirect to the relevant social site. * @param $socialDriver * @return \Symfony\Component\HttpFoundation\RedirectResponse + * @throws \BookStack\Exceptions\SocialDriverNotConfigured */ public function getSocialLogin($socialDriver) {