アクセス許可管理
諏訪子 <suwako@076.moe>、2025-12-29 15:53
コミット 8c76fe27330eb935e14b00e344111fe2ba1295d9
・親 decf69e
・ファイルを見る
14個のファイル、+126 -11
| @@ -0,0 +1,9 @@ | ||
| 1 | +title: 【新機能】メンバー限定 | |
| 2 | +uuid: d49f60c7-6d85-4263-9d3f-c20025f2fa0d | |
| 3 | +author: 諏訪子 | |
| 4 | +date: 2025-12-29 06:10:39 | |
| 5 | +thumbnail: | |
| 6 | +thumborient: center | |
| 7 | +category: feature,memberonly | |
| 8 | +---- | |
| 9 | +これを見れば、ログインしたユーザーという意味です。 |
| @@ -0,0 +1,9 @@ | ||
| 1 | +title: 【新機能】スタッフ限定 | |
| 2 | +uuid: 1c0ac334-a017-4813-9137-939b483c08eb | |
| 3 | +author: 諏訪子 | |
| 4 | +date: 2025-12-29 06:13:38 | |
| 5 | +thumbnail: | |
| 6 | +thumborient: center | |
| 7 | +category: feature,staffonly | |
| 8 | +---- | |
| 9 | +これを見れば、おいらのニッガーという意味です。 |
変更
newpost.php
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | if (!isset($argv[1])) die('usage: php newpost.php [slug]'); |
| 3 | 3 | if (file_exists("blog/{$argv[1]}.md")) die("エラー: ファイル「blog/{$argv[1]}.md」は既に存在します。\n"); |
| 4 | 4 | |
| 5 | +define('CURL_ENABLED', false); // 黙れ・・・ | |
| 5 | 6 | include('util.php'); |
| 6 | 7 | $post = fopen("blog/{$argv[1]}.md", "w"); |
| 7 | 8 | fwrite($post, "title: 【】\n"); |
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | public function feed(array $params): void { |
| 17 | 17 | try { |
| 18 | 18 | // 最新の投稿を取得 |
| 19 | - $posts = $this->getPosts('/blog/'); | |
| 19 | + $posts = $this->getPosts('/blog/', null); | |
| 20 | 20 | // 最新の5件に制限 |
| 21 | 21 | $posts = array_slice($posts, 0, 5); |
| 22 | 22 |
| @@ -7,9 +7,11 @@ | ||
| 7 | 7 | * |
| 8 | 8 | * @return array 投稿の配列 |
| 9 | 9 | */ |
| 10 | - public function getPosts(string $section): array { | |
| 10 | + public function getPosts(string $section, ?\stdClass $user): array { | |
| 11 | 11 | $path = ROOT.$section; |
| 12 | 12 | $posts = []; |
| 13 | + $isMember = $user !== NULL; | |
| 14 | + $isStaff = $user !== NULL && $user->role === 1; | |
| 13 | 15 | |
| 14 | 16 | if (!is_dir($path)) return $posts; |
| 15 | 17 | $files = glob($path.'/*.md'); |
| @@ -51,7 +53,7 @@ | ||
| 51 | 53 | 'thumborient' => $metadata['thumborient'] ?? '', |
| 52 | 54 | 'category' => $metadata['category'] ?? [], |
| 53 | 55 | 'uuid' => $metadata['uuid'] ?? '', |
| 54 | - 'preview' => $preview, | |
| 56 | + 'preview' => ((!$isMember && in_array('memberonly', $metadata['category'])) || (!$isStaff && in_array('staffonly', $metadata['category'])) ? '未許可' : $preview), | |
| 55 | 57 | 'slug' => $slug, |
| 56 | 58 | ]; |
| 57 | 59 | } |
| @@ -86,7 +86,7 @@ | ||
| 86 | 86 | |
| 87 | 87 | try { |
| 88 | 88 | header('Content-Type: application/activity+json'); |
| 89 | - $posts = $this->getPosts('/blog/'); | |
| 89 | + $posts = $this->getPosts('/blog/', null); | |
| 90 | 90 | $ap = new Activitypub($posts); |
| 91 | 91 | echo $ap->getActivity($uuid); |
| 92 | 92 | exit; |
| @@ -104,7 +104,7 @@ | ||
| 104 | 104 | public function apoutbox(array $params): void { |
| 105 | 105 | try { |
| 106 | 106 | header('Content-Type: application/activity+json'); |
| 107 | - $posts = $this->getPosts('/blog/'); | |
| 107 | + $posts = $this->getPosts('/blog/', null); | |
| 108 | 108 | $ap = new Activitypub($posts); |
| 109 | 109 | echo $ap->getOutbox(); |
| 110 | 110 | exit; |
| @@ -34,7 +34,11 @@ | ||
| 34 | 34 | |
| 35 | 35 | $description = 'テクニカル諏訪子ちゃんの個人ブログ'; |
| 36 | 36 | |
| 37 | - $posts = $this->getPosts('/blog/'); | |
| 37 | + // ユーザー | |
| 38 | + $auth = new Auth(); | |
| 39 | + $user = $auth->getLoggedInUser(); | |
| 40 | + | |
| 41 | + $posts = $this->getPosts('/blog/', $user); | |
| 38 | 42 | if (!is_array($posts)) $posts = []; |
| 39 | 43 | |
| 40 | 44 | // 検索機能が使用されている場合 |
| @@ -57,11 +61,7 @@ | ||
| 57 | 61 | $postsPerPage |
| 58 | 62 | ); |
| 59 | 63 | |
| 60 | - // ユーザー | |
| 61 | - $auth = new Auth(); | |
| 62 | - $user = $auth->getLoggedInUser(); | |
| 63 | 64 | $tmpl->assign('user', $user); |
| 64 | - | |
| 65 | 65 | $tmpl->assign('currentPage', $page); |
| 66 | 66 | $tmpl->assign('totalPages', $totalPages); |
| 67 | 67 | $tmpl->assign('posts', $currentPosts); |
| @@ -113,6 +113,8 @@ | ||
| 113 | 113 | // ユーザー |
| 114 | 114 | $auth = new Auth(); |
| 115 | 115 | $user = $auth->getLoggedInUser(); |
| 116 | + $isMember = $user !== NULL; | |
| 117 | + $isStaff = $user !== NULL && $user->role === 1; | |
| 116 | 118 | $tmpl->assign('user', $user); |
| 117 | 119 | |
| 118 | 120 | $tmpl->assign('pagetit', $pagetit); |
| @@ -130,10 +132,23 @@ | ||
| 130 | 132 | } |
| 131 | 133 | } |
| 132 | 134 | |
| 135 | + if (!$isMember && in_array('memberonly', $meta->category)) goto denyaccess; | |
| 136 | + if (!$isStaff && in_array('staffonly', $meta->category)) goto denyaccess; | |
| 137 | + | |
| 138 | +showpage: | |
| 133 | 139 | $tmpl->addCss('news-article'); |
| 134 | 140 | $tmpl->addCss('search'); |
| 135 | 141 | $tmpl->addCss('blogtype'); |
| 136 | 142 | $tmpl->render('article'); |
| 143 | + exit(); | |
| 144 | + | |
| 145 | +denyaccess: | |
| 146 | + unset($md, $meta, $pagetit, $article, $description); | |
| 147 | + $tmpl->assign('pagetit', 'Not found'); | |
| 148 | + $tmpl->assign('curPage', '404'); | |
| 149 | + $tmpl->assign('menu', $this->getMenu()); | |
| 150 | + $tmpl->assign('description', ''); | |
| 151 | + $tmpl->render('404'); | |
| 137 | 152 | } catch (\Exception $e) { |
| 138 | 153 | throw new \Exception($e->getMessage()); |
| 139 | 154 | } |
| @@ -32,6 +32,20 @@ | ||
| 32 | 32 | 'text' => '秘密のページ', |
| 33 | 33 | 'show' => false, |
| 34 | 34 | ], |
| 35 | + [ | |
| 36 | + 'class' => 'menu-item', | |
| 37 | + 'href' => '/memberonly', | |
| 38 | + 'page' => 'memberonly', | |
| 39 | + 'text' => 'メンバー限定', | |
| 40 | + 'show' => true, | |
| 41 | + ], | |
| 42 | + [ | |
| 43 | + 'class' => 'menu-item', | |
| 44 | + 'href' => '/staffonly', | |
| 45 | + 'page' => 'staffonly', | |
| 46 | + 'text' => 'スタッフ限定', | |
| 47 | + 'show' => true, | |
| 48 | + ], | |
| 35 | 49 | ]; |
| 36 | 50 | } |
| 37 | 51 | } |
| @@ -77,4 +77,54 @@ | ||
| 77 | 77 | throw new \Exception($e->getMessage()); |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | + | |
| 81 | + public function memberonly(array $params): void { | |
| 82 | + try { | |
| 83 | + $tmpl = new Template('/'); | |
| 84 | + $pagetit = 'サインインしたユーザー限定'; | |
| 85 | + $description = 'PHPフレームワークについて'; | |
| 86 | + | |
| 87 | + // ユーザー | |
| 88 | + $auth = new Auth(); | |
| 89 | + $user = $auth->getLoggedInUser(); | |
| 90 | + | |
| 91 | + $tmpl->assign('user', $user); | |
| 92 | + | |
| 93 | + $tmpl->assign('pagetit', $pagetit); | |
| 94 | + $tmpl->assign('curPage', 'memberonly'); | |
| 95 | + $tmpl->assign('custCss', false); | |
| 96 | + $tmpl->assign('menu', $this->getMenu()); | |
| 97 | + $tmpl->assign('description', $description); | |
| 98 | + | |
| 99 | + if ($user && $user->role != -1) $tmpl->render('memberonly'); | |
| 100 | + else $tmpl->render('nopermission'); | |
| 101 | + } catch (\Exception $e) { | |
| 102 | + throw new \Exception($e->getMessage()); | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + public function staffonly(array $params): void { | |
| 107 | + try { | |
| 108 | + $tmpl = new Template('/'); | |
| 109 | + $pagetit = 'スタッフ限定'; | |
| 110 | + $description = 'PHPフレームワークについて'; | |
| 111 | + | |
| 112 | + // ユーザー | |
| 113 | + $auth = new Auth(); | |
| 114 | + $user = $auth->getLoggedInUser(); | |
| 115 | + | |
| 116 | + $tmpl->assign('user', $user); | |
| 117 | + | |
| 118 | + $tmpl->assign('pagetit', $pagetit); | |
| 119 | + $tmpl->assign('curPage', 'staffonly'); | |
| 120 | + $tmpl->assign('custCss', false); | |
| 121 | + $tmpl->assign('menu', $this->getMenu()); | |
| 122 | + $tmpl->assign('description', $description); | |
| 123 | + | |
| 124 | + if ($user && $user->role == 1) $tmpl->render('staffonly'); | |
| 125 | + else $tmpl->render('nopermission'); | |
| 126 | + } catch (\Exception $e) { | |
| 127 | + throw new \Exception($e->getMessage()); | |
| 128 | + } | |
| 129 | + } | |
| 80 | 130 | } |
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 | |
| 51 | 51 | $test->it('アクティビティを受け取れるはず', function($test): void { |
| 52 | 52 | $blog = new BlogPost; |
| 53 | - $posts = $blog->getPosts('/blog/'); | |
| 53 | + $posts = $blog->getPosts('/blog/', null); | |
| 54 | 54 | $ap = new Activitypub($posts); |
| 55 | 55 | $res = $ap->getActivity('a8c04518-4181-4ec6-9ef0-3f88f23b84b6'); // /blog/feature-test |
| 56 | 56 | $test->assertNotNull($res); |
| @@ -0,0 +1,6 @@ | ||
| 1 | +{@ include(common/header) @} | |
| 2 | + <h1 class="paragraph">メンバー限定</h1> | |
| 3 | + <p class="paragraph"> | |
| 4 | + いらっしゃいませ、ご主人様! ^^) _旦~~ | |
| 5 | + </p> | |
| 6 | +{@ include(common/footer) @} |
| @@ -0,0 +1,3 @@ | ||
| 1 | +{@ include(common/header) @} | |
| 2 | + <p>表示許可却下。失礼。</p> | |
| 3 | +{@ include(common/footer) @} |
| @@ -0,0 +1,6 @@ | ||
| 1 | +{@ include(common/header) @} | |
| 2 | + <h1 class="paragraph">スタッフ限定</h1> | |
| 3 | + <p class="paragraph"> | |
| 4 | + よろしくね、社員。(´・ω・`) | |
| 5 | + </p> | |
| 6 | +{@ include(common/footer) @} |