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;
public function __construct(SocialAuthService $socialAuthService, LoginService $loginService)
{
$this->middleware('guest', ['only' => ['getLogin', 'login']]);
- $this->middleware('guard:standard,ldap', ['only' => ['login', 'logout']]);
+ $this->middleware('guard:standard,ldap', ['only' => ['login']]);
+ $this->middleware('guard:standard,ldap,oidc', ['only' => ['logout']]);
$this->socialAuthService = $socialAuthService;
$this->loginService = $loginService;
}
// Store the previous location for redirect after login
- $previous = url()->previous('');
- if ($previous && $previous !== url('/login') && setting('app-public')) {
- $isPreviousFromInstance = (strpos($previous, url('/')) === 0);
- if ($isPreviousFromInstance) {
- redirect()->setIntendedUrl($previous);
- }
- }
+ $this->updateIntendedFromPrevious();
return view('auth.login', [
'socialDrivers' => $socialDrivers,
*/
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);
$this->username() => [trans('auth.failed')],
])->redirectTo('/login');
}
+
+ /**
+ * Update the intended URL location from their previous URL.
+ * Ignores if not from the current app instance or if from certain
+ * login or authentication routes.
+ */
+ protected function updateIntendedFromPrevious(): void
+ {
+ // Store the previous location for redirect after login
+ $previous = url()->previous('');
+ $isPreviousFromInstance = (strpos($previous, url('/')) === 0);
+ if (!$previous || !setting('app-public') || !$isPreviousFromInstance) {
+ return;
+ }
+
+ $ignorePrefixList = [
+ '/login',
+ '/mfa',
+ ];
+
+ foreach ($ignorePrefixList as $ignorePrefix) {
+ if (strpos($previous, url($ignorePrefix)) === 0) {
+ return;
+ }
+ }
+
+ redirect()->setIntendedUrl($previous);
+ }
}