動いている

This commit is contained in:
2025-12-07 21:11:48 +09:00
parent e18de43d21
commit 229cc48cb5
4 changed files with 38 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ namespace Site\Controller;
use Site\Controller\BlogPost;
use Site\Controller\Mods;
use Site\Lib\Activitypub;
use Site\Lib\Auth;
use Site\Lib\Markdown;
use Site\Lib\Template;
@@ -56,6 +57,11 @@ class Home extends BlogPost {
$postsPerPage
);
// ユーザー
$auth = new Auth();
$user = $auth->getLoggedInUser();
$tmpl->assign('user', $user);
$tmpl->assign('currentPage', $page);
$tmpl->assign('totalPages', $totalPages);
$tmpl->assign('posts', $currentPosts);
@@ -104,6 +110,11 @@ class Home extends BlogPost {
$meta->title = $this->highlightTextContent($meta->title, $keywords);
}
// ユーザー
$auth = new Auth();
$user = $auth->getLoggedInUser();
$tmpl->assign('user', $user);
$tmpl->assign('pagetit', $pagetit);
$tmpl->assign('curPage', 'blog');
$tmpl->assign('custCss', false);

View File

@@ -2,6 +2,7 @@
namespace Site\Controller;
use Site\Controller\Mods;
use Site\Lib\Auth;
use Site\Lib\Template;
class Page {
@@ -13,6 +14,11 @@ class Page {
$pagetit = '新ページ';
$description = 'PHPフレームワークについて';
// ユーザー
$auth = new Auth();
$user = $auth->getLoggedInUser();
$tmpl->assign('user', $user);
$tmpl->assign('pagetit', $pagetit);
$tmpl->assign('curPage', 'about');
$tmpl->assign('custCss', false);
@@ -31,6 +37,11 @@ class Page {
$pagetit = 'モネロXMRで支援♡';
$description = 'テクニカル諏訪子ちゃんをモネロで支援♡';
// ユーザー
$auth = new Auth();
$user = $auth->getLoggedInUser();
$tmpl->assign('user', $user);
$tmpl->assign('pagetit', $pagetit);
$tmpl->assign('curPage', 'support');
$tmpl->assign('custCss', true);
@@ -50,6 +61,11 @@ class Page {
$pagetit = '秘密のページ';
$description = 'ケロ';
// ユーザー
$auth = new Auth();
$user = $auth->getLoggedInUser();
$tmpl->assign('user', $user);
$tmpl->assign('pagetit', $pagetit);
$tmpl->assign('curPage', 'support');
$tmpl->assign('custCss', false);
@@ -61,4 +77,4 @@ class Page {
throw new \Exception($e->getMessage());
}
}
}
}

View File

@@ -72,4 +72,4 @@ class User {
throw new \Exception($e->getMessage());
}
}
}
}

View File

@@ -85,7 +85,7 @@ class Auth {
$token = bin2hex(random_bytes(64));
$expire = time() + $this->tokenDuration;
$newToken = [
'token' => password_hash($token, $algo),
'token' => $token,
'ip' => $ip,
'createDate' => time(),
'expDate' => $expire,
@@ -151,7 +151,7 @@ class Auth {
return \Result::success();
}
public function isUserExist(?string $username): \Result {
public function isUserExist(?string $username = null): \Result {
if (null === $username) return \Result::Error('エラー:ユーザー名をご入力下さい。');
$userList = scandir($this->dataDir);
@@ -167,7 +167,7 @@ class Auth {
////////////////////
private function purgeOldTokens(\stdClass $userData): \stdClass {
private function purgeOldTokens(\stdClass $userData): \stdClass|\Result {
// 有効期限切れたトークンの削除
$out = $userData;
$out->tokens = array_filter($userData->tokens, function($t): bool {
@@ -196,8 +196,12 @@ class Auth {
$path = "{$this->dataDir}{$f}";
if (!is_file($path)) continue;
$content = file_get_contents($path);
if (str_contains($content, $token)) {
if ($token && str_contains($content, $token)) {
$matches[] = $path;
break;
} else if (!$token && str_contains($content, '"username": "'.$username.'",')) {
$matches[] = $path;
break;
}
}
$id = (int)preg_replace('/^(.*?)\.(.*?)$/', "$1", str_replace($this->dataDir, '', $matches[0]));
@@ -277,4 +281,4 @@ class Auth {
return \Result::Success();
}
};
};