cmvr-visual/backend/app/core/public_preflight.py
zhanghao 88cf14d794 feat: consolidate story studio and editable automatic production
Restructure backend and frontend modules; add story, library, and editor schema migrations.

Support editable automatic production, manual confirmation modes, account and user lifecycle management, compact container scrolling, consistent forms, and per-task result previews.

Update inference and TTS scheduling, deployment guidance, and regression coverage; remove obsolete standalone pages and temporary acceptance artifacts.
2026-11-14 14:07:26 +08:00

35 lines
1.3 KiB
Python

"""Fail closed when the operator explicitly enables Internet access."""
import asyncio
from sqlalchemy import select
from app.core.security import verify_password
from app.models import User
async def require_public_ready(db, settings):
if not settings.public_access:
return
if not settings.cookie_secure:
raise ValueError("PUBLIC_ACCESS requires COOKIE_SECURE and HTTPS")
if (settings.sqlalchemy_url.username or "").lower() == "root":
raise ValueError("PUBLIC_ACCESS requires a dedicated MySQL application user")
async with db.session() as session:
admins = (
await session.scalars(
select(User).where(User.role == "admin", User.disabled.is_(False))
)
).all()
if not admins:
raise ValueError("Public access requires an enabled administrator")
initial_passwords = {"123456"}
if settings.admin_password:
initial_passwords.add(settings.admin_password)
for user in admins:
unchanged = user.must_change_password
for password in initial_passwords:
unchanged |= await asyncio.to_thread(verify_password, password, user.password_hash)
if unchanged:
raise ValueError(
"Change the initial administrator password in private mode before PUBLIC_ACCESS"
)