動いている
諏訪子 <suwako@076.moe>、2025-12-07 21:11
コミット 229cc48cb51c7a2d0cfaed048171fb9827af2a9b
・親 e18de43
・ファイルを見る
4個のファイル、+37 -6
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | use Site\Controller\BlogPost; |
| 5 | 5 | use Site\Controller\Mods; |
| 6 | 6 | use Site\Lib\Activitypub; |
| 7 | +use Site\Lib\Auth; | |
| 7 | 8 | use Site\Lib\Markdown; |
| 8 | 9 | use Site\Lib\Template; |
| 9 | 10 | |
| @@ -56,6 +57,11 @@ | ||
| 56 | 57 | $postsPerPage |
| 57 | 58 | ); |
| 58 | 59 | |
| 60 | + // ユーザー | |
| 61 | + $auth = new Auth(); | |
| 62 | + $user = $auth->getLoggedInUser(); | |
| 63 | + $tmpl->assign('user', $user); | |
| 64 | + | |
| 59 | 65 | $tmpl->assign('currentPage', $page); |
| 60 | 66 | $tmpl->assign('totalPages', $totalPages); |
| 61 | 67 | $tmpl->assign('posts', $currentPosts); |
| @@ -103,6 +109,11 @@ | ||
| 103 | 109 | $article = $this->highlightTextContent($article, $keywords); |
| 104 | 110 | $meta->title = $this->highlightTextContent($meta->title, $keywords); |
| 105 | 111 | } |
| 112 | + | |
| 113 | + // ユーザー | |
| 114 | + $auth = new Auth(); | |
| 115 | + $user = $auth->getLoggedInUser(); | |
| 116 | + $tmpl->assign('user', $user); | |
| 106 | 117 | |
| 107 | 118 | $tmpl->assign('pagetit', $pagetit); |
| 108 | 119 | $tmpl->assign('curPage', 'blog'); |
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | namespace Site\Controller; |
| 3 | 3 | |
| 4 | 4 | use Site\Controller\Mods; |
| 5 | +use Site\Lib\Auth; | |
| 5 | 6 | use Site\Lib\Template; |
| 6 | 7 | |
| 7 | 8 | class Page { |
| @@ -13,6 +14,11 @@ | ||
| 13 | 14 | $pagetit = '新ページ'; |
| 14 | 15 | $description = 'PHPフレームワークについて'; |
| 15 | 16 | |
| 17 | + // ユーザー | |
| 18 | + $auth = new Auth(); | |
| 19 | + $user = $auth->getLoggedInUser(); | |
| 20 | + $tmpl->assign('user', $user); | |
| 21 | + | |
| 16 | 22 | $tmpl->assign('pagetit', $pagetit); |
| 17 | 23 | $tmpl->assign('curPage', 'about'); |
| 18 | 24 | $tmpl->assign('custCss', false); |
| @@ -31,6 +37,11 @@ | ||
| 31 | 37 | $pagetit = 'モネロ(XMR)で支援♡'; |
| 32 | 38 | $description = 'テクニカル諏訪子ちゃんをモネロで支援♡'; |
| 33 | 39 | |
| 40 | + // ユーザー | |
| 41 | + $auth = new Auth(); | |
| 42 | + $user = $auth->getLoggedInUser(); | |
| 43 | + $tmpl->assign('user', $user); | |
| 44 | + | |
| 34 | 45 | $tmpl->assign('pagetit', $pagetit); |
| 35 | 46 | $tmpl->assign('curPage', 'support'); |
| 36 | 47 | $tmpl->assign('custCss', true); |
| @@ -49,6 +60,11 @@ | ||
| 49 | 60 | $tmpl = new Template('/'); |
| 50 | 61 | $pagetit = '秘密のページ'; |
| 51 | 62 | $description = 'ケロ'; |
| 63 | + | |
| 64 | + // ユーザー | |
| 65 | + $auth = new Auth(); | |
| 66 | + $user = $auth->getLoggedInUser(); | |
| 67 | + $tmpl->assign('user', $user); | |
| 52 | 68 | |
| 53 | 69 | $tmpl->assign('pagetit', $pagetit); |
| 54 | 70 | $tmpl->assign('curPage', 'support'); |
| @@ -72,4 +72,4 @@ | ||
| 72 | 72 | throw new \Exception($e->getMessage()); |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | -} | |
| 75 | +} |
| @@ -85,7 +85,7 @@ | ||
| 85 | 85 | $token = bin2hex(random_bytes(64)); |
| 86 | 86 | $expire = time() + $this->tokenDuration; |
| 87 | 87 | $newToken = [ |
| 88 | - 'token' => password_hash($token, $algo), | |
| 88 | + 'token' => $token, | |
| 89 | 89 | 'ip' => $ip, |
| 90 | 90 | 'createDate' => time(), |
| 91 | 91 | 'expDate' => $expire, |
| @@ -151,7 +151,7 @@ | ||
| 151 | 151 | return \Result::success(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - public function isUserExist(?string $username): \Result { | |
| 154 | + public function isUserExist(?string $username = null): \Result { | |
| 155 | 155 | if (null === $username) return \Result::Error('エラー:ユーザー名をご入力下さい。'); |
| 156 | 156 | $userList = scandir($this->dataDir); |
| 157 | 157 | |
| @@ -167,7 +167,7 @@ | ||
| 167 | 167 | |
| 168 | 168 | //////////////////// |
| 169 | 169 | |
| 170 | - private function purgeOldTokens(\stdClass $userData): \stdClass { | |
| 170 | + private function purgeOldTokens(\stdClass $userData): \stdClass|\Result { | |
| 171 | 171 | // 有効期限切れたトークンの削除 |
| 172 | 172 | $out = $userData; |
| 173 | 173 | $out->tokens = array_filter($userData->tokens, function($t): bool { |
| @@ -196,8 +196,12 @@ | ||
| 196 | 196 | $path = "{$this->dataDir}{$f}"; |
| 197 | 197 | if (!is_file($path)) continue; |
| 198 | 198 | $content = file_get_contents($path); |
| 199 | - if (str_contains($content, $token)) { | |
| 199 | + if ($token && str_contains($content, $token)) { | |
| 200 | 200 | $matches[] = $path; |
| 201 | + break; | |
| 202 | + } else if (!$token && str_contains($content, '"username": "'.$username.'",')) { | |
| 203 | + $matches[] = $path; | |
| 204 | + break; | |
| 201 | 205 | } |
| 202 | 206 | } |
| 203 | 207 | $id = (int)preg_replace('/^(.*?)\.(.*?)$/', "$1", str_replace($this->dataDir, '', $matches[0])); |
| @@ -277,4 +281,4 @@ | ||
| 277 | 281 | |
| 278 | 282 | return \Result::Success(); |
| 279 | 283 | } |
| 280 | -}; | |
| 284 | +}; |