use BookStack\Auth\Access\SocialAuthService;
use BookStack\Exceptions\LoginAttemptEmailNeededException;
use BookStack\Exceptions\LoginAttemptException;
+use BookStack\Exceptions\UserRegistrationException;
use BookStack\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
*/
public function __construct(SocialAuthService $socialAuthService)
{
- $this->middleware('guest', ['only' => ['getLogin', 'postLogin']]);
+ $this->middleware('guest', ['only' => ['getLogin', 'login']]);
+ $this->middleware('guard:standard,ldap', ['only' => ['login', 'logout']]);
+
$this->socialAuthService = $socialAuthService;
$this->redirectPath = url('/');
$this->redirectAfterLogout = url('/login');
{
$socialDrivers = $this->socialAuthService->getActiveDrivers();
$authMethod = config('auth.method');
- $samlEnabled = config('saml2.enabled') === true;
if ($request->has('email')) {
session()->flashInput([
]);
}
+ $previous = url()->previous('');
+ if (setting('app-public') && $previous && $previous !== url('/login')) {
+ redirect()->setIntendedUrl($previous);
+ }
+
return view('auth.login', [
'socialDrivers' => $socialDrivers,
'authMethod' => $authMethod,
- 'samlEnabled' => $samlEnabled,
]);
}
return $this->sendFailedLoginResponse($request);
}
+ /**
+ * Validate the user login request.
+ *
+ * @param \Illuminate\Http\Request $request
+ * @return void
+ *
+ * @throws \Illuminate\Validation\ValidationException
+ */
+ protected function validateLogin(Request $request)
+ {
+ $rules = ['password' => 'required|string'];
+ $authMethod = config('auth.method');
+
+ if ($authMethod === 'standard') {
+ $rules['email'] = 'required|email';
+ }
+
+ if ($authMethod === 'ldap') {
+ $rules['username'] = 'required|string';
+ $rules['email'] = 'email';
+ }
+
+ $request->validate($rules);
+ }
+
/**
* Send a response when a login attempt exception occurs.
*/
return redirect('/login');
}
- /**
- * Log the user out of the application.
- */
- public function logout(Request $request)
- {
- if (config('saml2.enabled') && session()->get('last_login_type') === 'saml2') {
- return redirect('/saml2/logout');
- }
-
- $this->guard()->logout();
- $request->session()->invalidate();
-
- return $this->loggedOut($request) ?: redirect('/');
- }
}