diff --git a/api/router.py b/api/router.py index 42d8c98..8af125a 100644 --- a/api/router.py +++ b/api/router.py @@ -54,6 +54,34 @@ async def logout(authorization: Optional[str] = Header(None)): return {"ok": True} +@router.get("/setup") +async def setup_page(): + from fastapi.responses import FileResponse + from auth import has_users + from pathlib import Path + if has_users(): + from fastapi.responses import RedirectResponse + return RedirectResponse("/") + return FileResponse(str(Path(__file__).parent.parent / "frontend" / "setup.html")) + + +@router.post("/setup") +async def setup_post(body: dict): + from auth import has_users, create_user + from config import load as load_config + if has_users(): + raise HTTPException(status_code=403, detail="Bereits eingerichtet") + username = body.get("username", "").strip() + password = body.get("password", "") + if not username or len(password) < 6: + raise HTTPException(status_code=400, detail="Ungültige Eingabe") + cfg = load_config() + default_dir = cfg["output"]["path"] + output_dir = body.get("output_dir") or default_dir + create_user(username, password, output_dir, is_admin=True) + return {"ok": True} + + # --------------------------------------------------------------------------- # Protected endpoints # --------------------------------------------------------------------------- diff --git a/frontend/setup.html b/frontend/setup.html new file mode 100644 index 0000000..e261448 --- /dev/null +++ b/frontend/setup.html @@ -0,0 +1,147 @@ + + + + + + tüit Transkriptor — Ersteinrichtung + + + + + +
+ +

Ersteinrichtung — lege den Administrator-Account an.

+ +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + +
+ + + + diff --git a/main.py b/main.py index 8292ec4..554903f 100644 --- a/main.py +++ b/main.py @@ -129,10 +129,6 @@ def run_server(config: uvicorn.Config): # ── Entrypoint ───────────────────────────────────────────────────────────────── if __name__ == "__main__": - from auth import setup_wizard, has_users - if not has_users(): - setup_wizard() - cfg = load_config() port = cfg["server"]["port"] host = cfg.get("network", {}).get("host", "127.0.0.1") @@ -152,7 +148,9 @@ if __name__ == "__main__": break time.sleep(0.1) - webbrowser.open(f"http://localhost:{port}") + from auth import has_users + start_path = "/setup" if not has_users() else "/" + webbrowser.open(f"http://localhost:{port}{start_path}") try: run_tray(port)