aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front/controller/admin/ManageShaareController.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-16 20:17:08 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-27 19:32:57 +0100
commit9c04921a8c28c18ef757f2d43ba35e7e2a7f1a4b (patch)
treebcc2cb0dbad3ea27c38e676a20f3a377b50e9066 /application/front/controller/admin/ManageShaareController.php
parente6215a2ad97182efcf88ef532ec6bd65ae35fd19 (diff)
downloadShaarli-9c04921a8c28c18ef757f2d43ba35e7e2a7f1a4b.tar.gz
Shaarli-9c04921a8c28c18ef757f2d43ba35e7e2a7f1a4b.tar.zst
Shaarli-9c04921a8c28c18ef757f2d43ba35e7e2a7f1a4b.zip
Feature: Share private bookmarks using a URL containing a private key
- Add a share link next to « Permalink » in linklist (using share icon from fork awesome) - This link generates a private key associated to the bookmark - Accessing the bookmark while logged out with the proper key will display it Fixes #475
Diffstat (limited to 'application/front/controller/admin/ManageShaareController.php')
-rw-r--r--application/front/controller/admin/ManageShaareController.php26
1 files changed, 26 insertions, 0 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