内容后台上线:网页里改网站内容(账号密码 + 首次强制改密 + 草稿/预览/发布/回滚 + 画展传图);新世界线自动排位;星球预设 18 种

Browse Source
- backend-site/cms.py(新):账号(scrypt 加盐哈希)、服务端会话(只存哈希,30 天滑动,可撤销)、
  admin/admin 首次登录强制改密(改密前其它接口一律 403)、CSRF / 来源 / https / 登录冷却、
  内容校验、发布写 content/ 与 prices.json / payinfo.json、版本与回滚、传图核验 + 去元数据 + ffmpeg 缩略图
- server.py 把 /api/cms/* 交给 cms.py;admin.py 加 user list/add/passwd/reset/disable/enable/sessions
- portal/admin/(新):内容后台页面;门户顶栏加不带字的淡色铅笔入口
- 门户 / 下单页读 content/site.js、order/content/order.js(代码里的数据降级为兜底);?preview=1 预览草稿
- portal/assets/universe/layout.js(新):新点亮的世界线自动排到中圈不挤的位置、补给线接附近的星、已有的都不动
- planets.js:加 10 种卡通预设(类地 / 海洋 / 丛林 / 荒漠 / 冻原 / 熔岩 / 毒雾 / 荒芜岩球 / 冰巨星 / 带环巨星)
- galaxy.js:名牌 / 档案卡文字一律转义
- tests/内容后台测试.py(75 条);回归 27 + 数据库 38 照旧全过;端到端浏览器 36 条
- 文档:交接文档-2026-10.md(变更 / 接口 / 部署 7.1b / 测试 / 第 10 节)、内容后台设计.md(实现对照)、星系图交接说明、nginx 片段 ④

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yws
2026-10-05 21:25:06 +00:00
co-authored by Claude Opus 5.5
parent 6b05fc849a
commit 12e66badc6
24 changed files with 3607 additions and 62 deletions
+72 -1
View File
@@ -15,6 +15,12 @@
python3 admin.py sweep 清理超过保留期的成品 python3 admin.py sweep 清理超过保留期的成品
python3 admin.py stat 概览 python3 admin.py stat 概览
python3 admin.py db [check|backup|export [目录]] 数据库:体检 / 热备份 / 导回旧版 JSON python3 admin.py db [check|backup|export [目录]] 数据库:体检 / 热备份 / 导回旧版 JSON
python3 admin.py user list 内容后台:有哪些账号、最近登录
python3 admin.py user add <用户名> [--email 邮箱] [--temp] 建账号(密码隐藏输入两遍;--temp = 发临时密码、首次登录必须改)
python3 admin.py user passwd <账号> 直接设新密码(这个账号所有会话作废)
python3 admin.py user reset <账号> [--to-admin] 忘了密码:会话全作废 → 临时密码 → 下次登录必须改
python3 admin.py user disable|enable <账号> 停用 / 启用(停用时会话全作废)
python3 admin.py user sessions <账号> [--revoke-all] 在哪些设备登录着 / 全部踢掉
python3 admin.py audit [行数] 看兑换码失败/被拒记录 python3 admin.py audit [行数] 看兑换码失败/被拒记录
""" """
import csv, json, os, shutil, sys, time import csv, json, os, shutil, sys, time
@@ -288,6 +294,71 @@ def cmd_db(argv):
print("用法:admin.py db [check|backup|export [目录]]") print("用法:admin.py db [check|backup|export [目录]]")
def cmd_user(argv):
"""内容后台的账号(2026-10-05)。账号只能在服务器上用命令行建 —— 网页上没有注册入口。"""
import getpass
from datetime import datetime as _dt
sub, rest = (argv[0] if argv else "list"), argv[1:]
C = S.CMS
fmt = lambda ts: _dt.fromtimestamp(ts).strftime("%Y-%m-%d %H:%M") if ts else "从没登录过"
def ask_pw():
a = getpass.getpass("新密码(至少 %d 位):" % S.cms.MIN_PW)
if getpass.getpass("再输一遍:") != a:
sys.exit("两次输的不一样")
p = S.cms.pw_problem(a)
if p:
sys.exit(p)
return a
try:
if sub == "list":
for u in C.users():
print("%-16s %-28s %s%s 最近登录 %s(%s) 登录着 %d 台" % (
u["user"], u["email"] or "-", "【待改密】" if u["must_change"] else "", "【已停用】" if u["disabled"] else "",
fmt(u["last_login"]), u["last_ip"] or "-", u["sessions"]))
elif sub == "add" and rest:
email = rest[rest.index("--email") + 1] if "--email" in rest else None
import re as _re # 先校验,再问密码(不然填了半天密码才告诉你用户名不行)
if not _re.match(r"^[A-Za-z0-9_.-]{2,32}$", rest[0]):
sys.exit("用户名只能是 2–32 位字母、数字、点、横线、下划线")
if C.user_row(rest[0]) or (email and C.user_row(email)):
sys.exit("用户名或邮箱已经有人用了")
if "--temp" in rest:
import secrets as _sec
pw = _sec.token_urlsafe(9)
C.user_add(rest[0], pw, email, must_change=True)
print("建好了。临时密码:%s\n(只显示这一次;他第一次登录必须改密码)" % pw)
else:
C.user_add(rest[0], ask_pw(), email)
print("建好了:%s" % rest[0])
elif sub == "passwd" and rest:
name = C.user_set_password(rest[0], ask_pw())
C.audit("命令行", "-", "设了 %s 的新密码(所有会话已作废)" % name)
print("改好了;%s 所有登录着的设备都已退出" % name)
elif sub == "reset" and rest:
tmp = C.user_reset(rest[0], to_admin="--to-admin" in rest)
print("重置好了。临时密码:%s\n所有会话已作废;下次登录必须改密码。(临时密码只显示这一次)" % tmp)
elif sub in ("disable", "enable") and rest:
C.user_disable(rest[0], off=(sub == "disable"))
print("已%s:%s" % ("停用" if sub == "disable" else "启用", rest[0]))
elif sub == "sessions" and rest:
if "--revoke-all" in rest:
print("踢掉了 %d 个会话" % C.revoke_all(rest[0]))
else:
r = C.user_row(rest[0])
if not r:
sys.exit("没有这个账号")
rows = C.sessions_of(r[0])
if not rows:
print("(没有登录着的设备)")
for s in rows:
print("%s 最近 %s %s %s%s" % (s["id"], fmt(s["last"]), s["ip"], (s["ua"] or "")[:50], " 记住我" if s["remember"] else ""))
else:
print(__doc__)
except S.cms.Bad as e:
sys.exit(str(e))
def cmd_calls(argv): def cmd_calls(argv):
rows = S.STORE.calls() # 数据库 calls 表(2026-10-05 起;calls.jsonl 只是给手机通知的副本) rows = S.STORE.calls() # 数据库 calls 表(2026-10-05 起;calls.jsonl 只是给手机通知的副本)
if not rows: if not rows:
@@ -553,7 +624,7 @@ def cmd_gift(argv):
CMDS = {"gen": cmd_gen, "codes": cmd_codes, "ls": cmd_ls, "show": cmd_show, CMDS = {"gen": cmd_gen, "codes": cmd_codes, "ls": cmd_ls, "show": cmd_show,
"gift": cmd_gift, "gift": cmd_gift,
"price": cmd_price, "price": cmd_price,
"retry": cmd_retry, "calls": cmd_calls, "db": cmd_db, "sweep": cmd_sweep, "stat": cmd_stat, "retry": cmd_retry, "calls": cmd_calls, "db": cmd_db, "user": cmd_user, "sweep": cmd_sweep, "stat": cmd_stat,
"audit": cmd_audit, "activate": cmd_activate, "pending": cmd_pending, "audit": cmd_audit, "activate": cmd_activate, "pending": cmd_pending,
"edit": cmd_edit} "edit": cmd_edit}