Fix support for legacy route login redirection

Makes sure that the user is properly redirected to the bookmark form after login, even with legacy routes
This commit is contained in:
ArthurHoaro 2020-09-01 10:12:54 +02:00
parent bea062149e
commit aca995e09c
2 changed files with 8 additions and 6 deletions

View file

@ -42,7 +42,7 @@ public function post(Request $request, Response $response): Response
$parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : '';
if (!$this->container->loginManager->isLoggedIn()) { if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login' . $parameters); return $this->redirect($response, '/login?returnurl=/admin/shaare' . $parameters);
} }
return $this->redirect($response, '/admin/shaare' . $parameters); return $this->redirect($response, '/admin/shaare' . $parameters);
@ -52,7 +52,7 @@ public function post(Request $request, Response $response): Response
protected function addlink(Request $request, Response $response): Response protected function addlink(Request $request, Response $response): Response
{ {
if (!$this->container->loginManager->isLoggedIn()) { if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login'); return $this->redirect($response, '/login?returnurl=/admin/add-shaare');
} }
return $this->redirect($response, '/admin/add-shaare'); return $this->redirect($response, '/admin/add-shaare');
@ -61,7 +61,9 @@ protected function addlink(Request $request, Response $response): Response
/** Legacy route: ?do=login */ /** Legacy route: ?do=login */
protected function login(Request $request, Response $response): Response protected function login(Request $request, Response $response): Response
{ {
return $this->redirect($response, '/login'); $returnurl = $request->getQueryParam('returnurl');
return $this->redirect($response, '/login' . ($returnurl ? '?returnurl=' . $returnurl : ''));
} }
/** Legacy route: ?do=logout */ /** Legacy route: ?do=logout */

View file

@ -66,11 +66,11 @@ public function getProcessProvider(): array
{ {
return [ return [
['post', [], '/admin/shaare', true], ['post', [], '/admin/shaare', true],
['post', [], '/login', false], ['post', [], '/login?returnurl=/admin/shaare', false],
['post', ['title' => 'test'], '/admin/shaare?title=test', true], ['post', ['title' => 'test'], '/admin/shaare?title=test', true],
['post', ['title' => 'test'], '/login?title=test', false], ['post', ['title' => 'test'], '/login?returnurl=/admin/shaare?title=test', false],
['addlink', [], '/admin/add-shaare', true], ['addlink', [], '/admin/add-shaare', true],
['addlink', [], '/login', false], ['addlink', [], '/login?returnurl=/admin/add-shaare', false],
['login', [], '/login', true], ['login', [], '/login', true],
['login', [], '/login', false], ['login', [], '/login', false],
['logout', [], '/admin/logout', true], ['logout', [], '/admin/logout', true],