Fix CMS login and restore PAGEPAN feature icons

This commit is contained in:
2026-11-21 18:47:07 +08:00
parent d9bda755d1
commit 908f9385fb
32 changed files with 519 additions and 156 deletions
+19 -5
View File
@@ -5,14 +5,17 @@ declare(strict_types=1);
require dirname(__DIR__) . '/vendor/autoload.php';
use App\Content\Database;
use App\Content\Passwords;
use App\Content\Repository;
$email = strtolower(trim($argv[1] ?? ''));
$reset = ($argv[1] ?? '') === 'reset';
$email = strtolower(trim($argv[$reset ? 2 : 1] ?? ''));
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
fwrite(STDERR, "用法:php bin/admin.php admin@example.com\n");
fwrite(STDERR, "用法:php bin/admin.php [reset] admin@example.com\n");
exit(1);
}
fwrite(STDERR, "请输入至少 12 字符的管理员密码:");
fwrite(STDERR, "请输入至少 8 字符的管理员密码:");
$tty = function_exists('stream_isatty') && stream_isatty(STDIN);
if ($tty) {
exec('stty -echo');
@@ -25,13 +28,24 @@ try {
}
fwrite(STDERR, "\n");
}
if (mb_strlen($password) < 12 || strlen($password) > 72 || str_contains($password, "\0")) {
fwrite(STDERR, "密码需至少 12 字符,并且最多 72 字节。\n");
if (!Passwords::isValidNew($password)) {
fwrite(STDERR, "密码至少 8 个字符,最多 72 字节。\n");
exit(1);
}
Database::initialize();
$hash = password_hash($password, PASSWORD_DEFAULT);
if ($reset) {
$repo = new Repository();
$user = $repo->administrator($email);
if (!$user || !$repo->changePassword($user, $hash)) {
fwrite(STDERR, "未能重设密码。请确认邮箱对应的账户存在,且未被同时修改。\n");
exit(1);
}
fwrite(STDOUT, "密码已重设,旧会话将失效。\n");
exit(0);
}
$query = Database::connect()->prepare('INSERT INTO users (email, password_hash) VALUES (?, ?)
ON CONFLICT (email) DO UPDATE SET password_hash = excluded.password_hash');
$query->execute([$email, $hash]);