namespace BookStack\Http\Controllers\Auth;
-use Activity;
use BookStack\Auth\Access\LoginService;
use BookStack\Auth\Access\SocialAuthService;
use BookStack\Exceptions\LoginAttemptEmailNeededException;
use BookStack\Exceptions\LoginAttemptException;
+use BookStack\Facades\Activity;
use BookStack\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
|
*/
- use AuthenticatesUsers;
+ use AuthenticatesUsers { logout as traitLogout; }
/**
* Redirection paths.
*/
protected $redirectTo = '/';
protected $redirectPath = '/';
- protected $redirectAfterLogout = '/login';
+ protected $redirectAfterLogout = '/';
protected $socialAuthService;
protected $loginService;
$this->loginService = $loginService;
$this->redirectPath = url('/');
- $this->redirectAfterLogout = url('/login');
+ $this->redirectAfterLogout = url(config('auth.auto_redirect') ? '/login?logout=1' : '/');
}
public function username()
{
$socialDrivers = $this->socialAuthService->getActiveDrivers();
$authMethod = config('auth.method');
+ $autoRedirect = config('auth.auto_redirect');
if ($request->has('email')) {
session()->flashInput([
// Store the previous location for redirect after login
$this->updateIntendedFromPrevious();
+ if ($autoRedirect && !($request->has('logout') && $request->get('logout') == '1') && count($socialDrivers) == 0 && in_array($authMethod, ['oidc', 'saml2'])) {
+ return view('auth.login-redirect', [
+ 'authMethod' => $authMethod,
+ ]);
+ }
+
return view('auth.login', [
'socialDrivers' => $socialDrivers,
'authMethod' => $authMethod,
*/
protected function validateLogin(Request $request)
{
- $rules = ['password' => 'required|string'];
+ $rules = ['password' => ['required', 'string']];
$authMethod = config('auth.method');
if ($authMethod === 'standard') {
- $rules['email'] = 'required|email';
+ $rules['email'] = ['required', 'email'];
}
if ($authMethod === 'ldap') {
- $rules['username'] = 'required|string';
- $rules['email'] = 'email';
+ $rules['username'] = ['required', 'string'];
+ $rules['email'] = ['email'];
}
$request->validate($rules);
redirect()->setIntendedUrl($previous);
}
+
+ /**
+ * Logout user and perform subsequent redirect.
+ *
+ * @param \Illuminate\Http\Request $request
+ *
+ * @return mixed
+ */
+ public function logout(Request $request)
+ {
+ $this->traitLogout($request);
+
+ return redirect($this->redirectAfterLogout);
+ }
}