diff options
Diffstat (limited to 'application/front')
-rw-r--r-- | application/front/controller/admin/ManageShaareController.php | 26 | ||||
-rw-r--r-- | application/front/controller/visitor/BookmarkListController.php | 4 |
2 files changed, 29 insertions, 1 deletions
diff --git a/application/front/controller/admin/ManageShaareController.php b/application/front/controller/admin/ManageShaareController.php index 908ebae3..e490f85a 100644 --- a/application/front/controller/admin/ManageShaareController.php +++ b/application/front/controller/admin/ManageShaareController.php | |||
@@ -321,6 +321,32 @@ class ManageShaareController extends ShaarliAdminController | |||
321 | } | 321 | } |
322 | 322 | ||
323 | /** | 323 | /** |
324 | * GET /admin/shaare/private/{hash} - Attach a private key to given bookmark, then redirect to the sharing URL. | ||
325 | */ | ||
326 | public function sharePrivate(Request $request, Response $response, array $args): Response | ||
327 | { | ||
328 | $this->checkToken($request); | ||
329 | |||
330 | $hash = $args['hash'] ?? ''; | ||
331 | $bookmark = $this->container->bookmarkService->findByHash($hash); | ||
332 | |||
333 | if ($bookmark->isPrivate() !== true) { | ||
334 | return $this->redirect($response, '/shaare/' . $hash); | ||
335 | } | ||
336 | |||
337 | if (empty($bookmark->getAdditionalContentEntry('private_key'))) { | ||
338 | $privateKey = bin2hex(random_bytes(16)); | ||
339 | $bookmark->addAdditionalContentEntry('private_key', $privateKey); | ||
340 | $this->container->bookmarkService->set($bookmark); | ||
341 | } | ||
342 | |||
343 | return $this->redirect( | ||
344 | $response, | ||
345 | '/shaare/' . $hash . '?key=' . $bookmark->getAdditionalContentEntry('private_key') | ||
346 | ); | ||
347 | } | ||
348 | |||
349 | /** | ||
324 | * Helper function used to display the shaare form whether it's a new or existing bookmark. | 350 | * Helper function used to display the shaare form whether it's a new or existing bookmark. |
325 | * | 351 | * |
326 | * @param array $link data used in template, either from parameters or from the data store | 352 | * @param array $link data used in template, either from parameters or from the data store |
diff --git a/application/front/controller/visitor/BookmarkListController.php b/application/front/controller/visitor/BookmarkListController.php index 5267c8f5..78c474c9 100644 --- a/application/front/controller/visitor/BookmarkListController.php +++ b/application/front/controller/visitor/BookmarkListController.php | |||
@@ -137,8 +137,10 @@ class BookmarkListController extends ShaarliVisitorController | |||
137 | */ | 137 | */ |
138 | public function permalink(Request $request, Response $response, array $args): Response | 138 | public function permalink(Request $request, Response $response, array $args): Response |
139 | { | 139 | { |
140 | $privateKey = $request->getParam('key'); | ||
141 | |||
140 | try { | 142 | try { |
141 | $bookmark = $this->container->bookmarkService->findByHash($args['hash']); | 143 | $bookmark = $this->container->bookmarkService->findByHash($args['hash'], $privateKey); |
142 | } catch (BookmarkNotFoundException $e) { | 144 | } catch (BookmarkNotFoundException $e) { |
143 | $this->assignView('error_message', $e->getMessage()); | 145 | $this->assignView('error_message', $e->getMessage()); |
144 | 146 | ||