Merge pull request #1534 from ArthurHoaro/fix/legacy-route-post

This commit is contained in:
ArthurHoaro 2020-09-03 08:35:05 +02:00 committed by GitHub
commit d95624add4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View file

@ -40,28 +40,33 @@ public function process(Request $request, Response $response, string $action): R
public function post(Request $request, Response $response): Response 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()) : '';
$route = '/admin/shaare';
if (!$this->container->loginManager->isLoggedIn()) { if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login' . $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= */ /** Legacy route: ?addlink= */
protected function addlink(Request $request, Response $response): Response protected function addlink(Request $request, Response $response): Response
{ {
$route = '/admin/add-shaare';
if (!$this->container->loginManager->isLoggedIn()) { if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login'); 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 */ /** 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 */
@ -127,4 +132,21 @@ protected function feed(Request $request, Response $response, string $feedType):
return $this->redirect($response, '/feed/' . $feedType . $parameters); return $this->redirect($response, '/feed/' . $feedType . $parameters);
} }
/** Legacy route: ?do=configure */
protected function configure(Request $request, Response $response): Response
{
$route = '/admin/configure';
if (!$this->container->loginManager->isLoggedIn()) {
return $this->redirect($response, '/login?returnurl=' . $this->getBasePath() . $route);
}
return $this->redirect($response, $route);
}
protected function getBasePath(): string
{
return $this->container->basePath ?: '';
}
} }

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=/subfolder/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=/subfolder/admin/shaare?title=test', false],
['addlink', [], '/admin/add-shaare', true], ['addlink', [], '/admin/add-shaare', true],
['addlink', [], '/login', false], ['addlink', [], '/login?returnurl=/subfolder/admin/add-shaare', false],
['login', [], '/login', true], ['login', [], '/login', true],
['login', [], '/login', false], ['login', [], '/login', false],
['logout', [], '/admin/logout', true], ['logout', [], '/admin/logout', true],
@ -94,6 +94,8 @@ public function getProcessProvider(): array
['opensearch', [], '/open-search', true], ['opensearch', [], '/open-search', true],
['dailyrss', [], '/daily-rss', false], ['dailyrss', [], '/daily-rss', false],
['dailyrss', [], '/daily-rss', true], ['dailyrss', [], '/daily-rss', true],
['configure', [], '/login?returnurl=/subfolder/admin/configure', false],
['configure', [], '/admin/configure', true],
]; ];
} }
} }