diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-27 19:40:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 19:40:57 +0100 |
commit | 977db7eabc30cd9d84f22330a114cb9d904cb514 (patch) | |
tree | bcc2cb0dbad3ea27c38e676a20f3a377b50e9066 /application/bookmark/BookmarkFileService.php | |
parent | e6215a2ad97182efcf88ef532ec6bd65ae35fd19 (diff) | |
parent | 9c04921a8c28c18ef757f2d43ba35e7e2a7f1a4b (diff) | |
download | Shaarli-977db7eabc30cd9d84f22330a114cb9d904cb514.tar.gz Shaarli-977db7eabc30cd9d84f22330a114cb9d904cb514.tar.zst Shaarli-977db7eabc30cd9d84f22330a114cb9d904cb514.zip |
Merge pull request #1597 from ArthurHoaro/feature/share-private-bookmark
Feature: Share private bookmarks using a URL containing a private key
Diffstat (limited to 'application/bookmark/BookmarkFileService.php')
-rw-r--r-- | application/bookmark/BookmarkFileService.php | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index eb7899bf..14b3d620 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php | |||
@@ -97,12 +97,15 @@ class BookmarkFileService implements BookmarkServiceInterface | |||
97 | /** | 97 | /** |
98 | * @inheritDoc | 98 | * @inheritDoc |
99 | */ | 99 | */ |
100 | public function findByHash(string $hash): Bookmark | 100 | public function findByHash(string $hash, string $privateKey = null): Bookmark |
101 | { | 101 | { |
102 | $bookmark = $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_HASH, $hash); | 102 | $bookmark = $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_HASH, $hash); |
103 | // PHP 7.3 introduced array_key_first() to avoid this hack | 103 | // PHP 7.3 introduced array_key_first() to avoid this hack |
104 | $first = reset($bookmark); | 104 | $first = reset($bookmark); |
105 | if (! $this->isLoggedIn && $first->isPrivate()) { | 105 | if (!$this->isLoggedIn |
106 | && $first->isPrivate() | ||
107 | && (empty($privateKey) || $privateKey !== $first->getAdditionalContentEntry('private_key')) | ||
108 | ) { | ||
106 | throw new Exception('Not authorized'); | 109 | throw new Exception('Not authorized'); |
107 | } | 110 | } |
108 | 111 | ||