Make install_server handle one-time admin bootstrap prompt

This commit is contained in:
Jage9
2026-02-24 22:11:10 -05:00
parent bf3bc90f2a
commit 404384416e
3 changed files with 74 additions and 2 deletions

View File

@@ -83,12 +83,17 @@ class AuthService:
def bootstrap_admin(self, username: str, password: str, email: str | None = None) -> AuthUser:
"""Create the first admin account, or fail if one already exists."""
existing = self._conn.execute("SELECT 1 FROM users WHERE role = 'admin' LIMIT 1").fetchone()
if existing is not None:
if self.has_admin():
raise AuthError("An admin account already exists.")
created = self.register(username, password, email=email, role="admin")
return created.user
def has_admin(self) -> bool:
"""Return True when at least one admin account exists."""
existing = self._conn.execute("SELECT 1 FROM users WHERE role = 'admin' LIMIT 1").fetchone()
return existing is not None
def register(
self,
username: str,