Fix legacy redirection when Shaarli instance is under a subfolder

This commit is contained in:
ArthurHoaro 2020-09-01 10:40:18 +02:00
parent aca995e09c
commit 9e2d47e519
2 changed files with 12 additions and 9 deletions

View file

@ -40,30 +40,33 @@ class LegacyController extends ShaarliVisitorController
public function post(Request $request, Response $response): Response
{
$parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : '';
$route = '/admin/shaare';
if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login?returnurl=/admin/shaare' . $parameters);
return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters);
}
return $this->redirect($response, '/admin/shaare' . $parameters);
return $this->redirect($response, $route . $parameters);
}
/** Legacy route: ?addlink= */
protected function addlink(Request $request, Response $response): Response
{
$route = '/admin/add-shaare';
if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login?returnurl=/admin/add-shaare');
return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route);
}
return $this->redirect($response, '/admin/add-shaare');
return $this->redirect($response, $route);
}
/** Legacy route: ?do=login */
protected function login(Request $request, Response $response): Response
{
$returnurl = $request->getQueryParam('returnurl');
$returnUrl = $request->getQueryParam('returnurl');
return $this->redirect($response, '/login' . ($returnurl ? '?returnurl=' . $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?returnurl=/admin/shaare', false],
['post', [], '/login?returnurl=/subfolder/admin/shaare', false],
['post', ['title' => 'test'], '/admin/shaare?title=test', true],
['post', ['title' => 'test'], '/login?returnurl=/admin/shaare?title=test', false],
['post', ['title' => 'test'], '/login?returnurl=/subfolder/admin/shaare?title=test', false],
['addlink', [], '/admin/add-shaare', true],
['addlink', [], '/login?returnurl=/admin/add-shaare', false],
['addlink', [], '/login?returnurl=/subfolder/admin/add-shaare', false],
['login', [], '/login', true],
['login', [], '/login', false],
['logout', [], '/admin/logout', true],