Use multi-level routes for existing controllers instead of 1 level everywhere
Also prefix most admin routes with /admin/
This commit is contained in:
parent
818b3193ff
commit
9c75f87793
42 changed files with 191 additions and 227 deletions
|
@ -38,9 +38,9 @@ class ShaarliMiddleware
|
|||
*/
|
||||
public function __invoke(Request $request, Response $response, callable $next)
|
||||
{
|
||||
try {
|
||||
$this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');
|
||||
$this->container->basePath = rtrim($request->getUri()->getBasePath(), '/');
|
||||
|
||||
try {
|
||||
$response = $next($request, $response);
|
||||
} catch (ShaarliFrontException $e) {
|
||||
$this->container->pageBuilder->assign('message', $e->getMessage());
|
||||
|
@ -54,7 +54,7 @@ class ShaarliMiddleware
|
|||
$response = $response->withStatus($e->getCode());
|
||||
$response = $response->write($this->container->pageBuilder->render('error'));
|
||||
} catch (UnauthorizedException $e) {
|
||||
return $response->withRedirect($request->getUri()->getBasePath() . '/login');
|
||||
return $response->withRedirect($this->container->basePath . '/login');
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
|
@ -19,7 +19,7 @@ use Throwable;
|
|||
class ConfigureController extends ShaarliAdminController
|
||||
{
|
||||
/**
|
||||
* GET /configure - Displays the configuration page
|
||||
* GET /admin/configure - Displays the configuration page
|
||||
*/
|
||||
public function index(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ class ConfigureController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* POST /configure - Update Shaarli's configuration
|
||||
* POST /admin/configure - Update Shaarli's configuration
|
||||
*/
|
||||
public function save(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -115,6 +115,6 @@ class ConfigureController extends ShaarliAdminController
|
|||
|
||||
$this->saveSuccessMessage(t('Configuration was saved.'));
|
||||
|
||||
return $response->withRedirect('./configure');
|
||||
return $this->redirect($response, '/admin/configure');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ class LogoutController extends ShaarliAdminController
|
|||
$this->container->sessionManager->logout();
|
||||
|
||||
// TODO: switch to a simple Cookie manager allowing to check the session, and create mocks.
|
||||
setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->webPath);
|
||||
setcookie(LoginManager::$STAY_SIGNED_IN_COOKIE, 'false', 0, $this->container->basePath . '/');
|
||||
|
||||
return $response->withRedirect('./');
|
||||
return $this->redirect($response, '/');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ use Slim\Http\Response;
|
|||
class ManageTagController extends ShaarliAdminController
|
||||
{
|
||||
/**
|
||||
* GET /manage-tags - Displays the manage tags page
|
||||
* GET /admin/tags - Displays the manage tags page
|
||||
*/
|
||||
public function index(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ class ManageTagController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* POST /manage-tags - Update or delete provided tag
|
||||
* POST /admin/tags - Update or delete provided tag
|
||||
*/
|
||||
public function save(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ class ManageTagController extends ShaarliAdminController
|
|||
if (0 === strlen($fromTag) || false === $isDelete && 0 === strlen($toTag)) {
|
||||
$this->saveWarningMessage(t('Invalid tags provided.'));
|
||||
|
||||
return $response->withRedirect('./manage-tags');
|
||||
return $this->redirect($response, '/admin/tags');
|
||||
}
|
||||
|
||||
// TODO: move this to bookmark service
|
||||
|
@ -80,8 +80,8 @@ class ManageTagController extends ShaarliAdminController
|
|||
|
||||
$this->saveSuccessMessage($alert);
|
||||
|
||||
$redirect = true === $isDelete ? './manage-tags' : './?searchtags='. urlencode($toTag);
|
||||
$redirect = true === $isDelete ? '/admin/tags' : '/?searchtags='. urlencode($toTag);
|
||||
|
||||
return $response->withRedirect($redirect);
|
||||
return $this->redirect($response, $redirect);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class PasswordController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* GET /password - Displays the change password template
|
||||
* GET /admin/password - Displays the change password template
|
||||
*/
|
||||
public function index(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ class PasswordController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* POST /password - Change admin password - existing and new passwords need to be provided.
|
||||
* POST /admin/password - Change admin password - existing and new passwords need to be provided.
|
||||
*/
|
||||
public function change(Request $request, Response $response): Response
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ use Slim\Http\Response;
|
|||
class PostBookmarkController extends ShaarliAdminController
|
||||
{
|
||||
/**
|
||||
* GET /add-shaare - Displays the form used to create a new bookmark from an URL
|
||||
* GET /admin/add-shaare - Displays the form used to create a new bookmark from an URL
|
||||
*/
|
||||
public function addShaare(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ class PostBookmarkController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* GET /shaare - Displays the bookmark form for creation.
|
||||
* GET /admin/shaare - Displays the bookmark form for creation.
|
||||
* Note that if the URL is found in existing bookmarks, then it will be in edit mode.
|
||||
*/
|
||||
public function displayCreateForm(Request $request, Response $response): Response
|
||||
|
@ -93,7 +93,7 @@ class PostBookmarkController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* GET /shaare-{id} - Displays the bookmark form in edition mode.
|
||||
* GET /admin/shaare/{id} - Displays the bookmark form in edition mode.
|
||||
*/
|
||||
public function displayEditForm(Request $request, Response $response, array $args): Response
|
||||
{
|
||||
|
@ -106,7 +106,7 @@ class PostBookmarkController extends ShaarliAdminController
|
|||
} catch (BookmarkNotFoundException $e) {
|
||||
$this->saveErrorMessage(t('Bookmark not found'));
|
||||
|
||||
return $response->withRedirect('./');
|
||||
return $this->redirect($response, '/');
|
||||
}
|
||||
|
||||
$formatter = $this->container->formatterFactory->getFormatter('raw');
|
||||
|
@ -116,7 +116,7 @@ class PostBookmarkController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
/**
|
||||
* POST /shaare
|
||||
* POST /admin/shaare
|
||||
*/
|
||||
public function save(Request $request, Response $response): Response
|
||||
{
|
||||
|
@ -170,11 +170,14 @@ class PostBookmarkController extends ShaarliAdminController
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /admin/shaare/delete
|
||||
*/
|
||||
public function deleteBookmark(Request $request, Response $response): Response
|
||||
{
|
||||
$this->checkToken($request);
|
||||
|
||||
$ids = escape(trim($request->getParam('lf_linkdate')));
|
||||
$ids = escape(trim($request->getParam('id')));
|
||||
if (strpos($ids, ' ') !== false) {
|
||||
// multiple, space-separated ids provided
|
||||
$ids = array_values(array_filter(preg_split('/\s+/', $ids), 'strlen'));
|
||||
|
@ -207,7 +210,7 @@ class PostBookmarkController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
// Don't redirect to where we were previously because the datastore has changed.
|
||||
return $response->withRedirect('./');
|
||||
return $this->redirect($response, '/');
|
||||
}
|
||||
|
||||
protected function displayForm(array $link, bool $isNew, Request $request, Response $response): Response
|
||||
|
|
|
@ -23,7 +23,7 @@ class LoginController extends ShaarliVisitorController
|
|||
if ($this->container->loginManager->isLoggedIn()
|
||||
|| $this->container->conf->get('security.open_shaarli', false)
|
||||
) {
|
||||
return $response->withRedirect('./');
|
||||
return $this->redirect($response, '/');
|
||||
}
|
||||
|
||||
$userCanLogin = $this->container->loginManager->canLogin($request->getServerParams());
|
||||
|
|
|
@ -104,6 +104,19 @@ abstract class ShaarliVisitorController
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple helper which prepend the base path to redirect path.
|
||||
*
|
||||
* @param Response $response
|
||||
* @param string $path Absolute path, e.g.: `/`, or `/admin/shaare/123` regardless of install directory
|
||||
*
|
||||
* @return Response updated
|
||||
*/
|
||||
protected function redirect(Response $response, string $path): Response
|
||||
{
|
||||
return $response->withRedirect($this->container->basePath . $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a redirection to the previous page, based on the HTTP_REFERER.
|
||||
* It fails back to the home page.
|
||||
|
|
|
@ -11,6 +11,8 @@ use Slim\Http\Response;
|
|||
* Class TagController
|
||||
*
|
||||
* Slim controller handle tags.
|
||||
*
|
||||
* TODO: check redirections with new helper
|
||||
*/
|
||||
class TagController extends ShaarliVisitorController
|
||||
{
|
||||
|
@ -27,10 +29,10 @@ class TagController extends ShaarliVisitorController
|
|||
// In case browser does not send HTTP_REFERER, we search a single tag
|
||||
if (null === $referer) {
|
||||
if (null !== $newTag) {
|
||||
return $response->withRedirect('./?searchtags='. urlencode($newTag));
|
||||
return $this->redirect($response, '/?searchtags='. urlencode($newTag));
|
||||
}
|
||||
|
||||
return $response->withRedirect('./');
|
||||
return $this->redirect($response, '/');
|
||||
}
|
||||
|
||||
$currentUrl = parse_url($referer);
|
||||
|
@ -81,7 +83,7 @@ class TagController extends ShaarliVisitorController
|
|||
|
||||
// If the referrer is not provided, we can update the search, so we failback on the bookmark list
|
||||
if (empty($referer)) {
|
||||
return $response->withRedirect('./');
|
||||
return $this->redirect($response, '/');
|
||||
}
|
||||
|
||||
$tagToRemove = $args['tag'] ?? null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue