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 @@ class LegacyController extends ShaarliVisitorController
$parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : '';
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);
@ -52,7 +52,7 @@ class LegacyController extends ShaarliVisitorController
protected function addlink(Request $request, Response $response): Response
{
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');
@ -61,7 +61,9 @@ class LegacyController extends ShaarliVisitorController
/** Legacy route: ?do=login */
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 */

View file

@ -66,11 +66,11 @@ class LegacyControllerTest extends TestCase
{
return [
['post', [], '/admin/shaare', true],
['post', [], '/login', false],
['post', [], '/login?returnurl=/admin/shaare', false],
['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', [], '/login', false],
['addlink', [], '/login?returnurl=/admin/add-shaare', false],
['login', [], '/login', true],
['login', [], '/login', false],
['logout', [], '/admin/logout', true],