use BookStack\Exceptions\AuthException;
use BookStack\Http\Controllers\Controller;
use BookStack\Repos\UserRepo;
+use BookStack\Repos\LdapRepo;
+use BookStack\Services\LdapService;
use BookStack\Services\SocialAuthService;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
protected function authenticated(Request $request, Authenticatable $user)
{
// Explicitly log them out for now if they do no exist.
- if (!$user->exists) auth()->logout($user);
+ if (!$user->exists) {
+ auth()->logout($user);
+ }
- if (!$user->exists && $user->email === null && !$request->has('email')) {
+ if (!$user->exists && $user->email === null && !$request->filled('email')) {
$request->flash();
session()->flash('request-email', true);
return redirect('/login');
}
- if (!$user->exists && $user->email === null && $request->has('email')) {
+ if (!$user->exists && $user->email === null && $request->filled('email')) {
$user->email = $request->get('email');
}
if (!$user->exists) {
-
// Check for users with same email already
$alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
if ($alreadyUser) {
auth()->login($user);
}
+ // ldap groups refresh
+ if (config('services.ldap.user_to_groups') !== false && $request->filled('username')) {
+ $ldapRepo = new LdapRepo($this->userRepo, app(LdapService::class));
+ $ldapRepo->syncGroups($user, $request->input('username'));
+ }
+
+
$path = session()->pull('url.intended', '/');
$path = baseUrl($path, true);
return redirect($path);
/**
* Show the application login form.
+ * @param Request $request
* @return \Illuminate\Http\Response
*/
- public function getLogin()
+ public function getLogin(Request $request)
{
$socialDrivers = $this->socialAuthService->getActiveDrivers();
$authMethod = config('auth.method');
+
+ if ($request->has('email')) {
+ session()->flashInput([
+ 'email' => $request->get('email'),
+ 'password' => (config('app.env') === 'demo') ? $request->get('password', '') : ''
+ ]);
+ }
+
return view('auth/login', ['socialDrivers' => $socialDrivers, 'authMethod' => $authMethod]);
}
session()->put('social-callback', 'login');
return $this->socialAuthService->startLogIn($socialDriver);
}
-}
\ No newline at end of file
+}