Add registration toggle and password change; genericise deploy
Two things the running instance needed. **Registration toggle.** Admin -> General, backed by a new settings table group rather than the environment. LEMBAS_ALLOW_SIGNUP now seeds only the initial value: once an administrator saves the setting, the stored value wins. The alternative -- environment always winning -- means a toggle in the UI silently reverts on the next restart, which is worse than not offering one. Closing registration also removes the "Create one" link from the sign-in page, so the link never leads somewhere that refuses. **Password change**, on the user settings page. Changing a password revokes every other session and immediately re-issues a cookie for the current one: if the reason for the change is that somebody else knows the password, leaving their session alive defeats the point, but signing the user out of the tab they are standing in is merely rude. **deploy/ is now host-agnostic.** This repository is public, so the unit and vhost became templates with __PREFIX__ / __SITE_HOST__ / __APP_PORT__ substituted at install time, and every path, hostname and port moved to environment variables. REPO_URL defaults to the checkout's own origin so a fork deploys itself. Machine-specific values belong in private notes, not here -- CLAUDE.md now says so. 83 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+39
-2
@@ -11,7 +11,8 @@ from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session as DBSession
|
||||
|
||||
from lembas.api.deps import AdminUser, Db
|
||||
from lembas.db.models import Connection, Model
|
||||
from lembas.db.models import Connection, Model, User
|
||||
from lembas.services import settings_store
|
||||
from lembas.services.crypto import decrypt, encrypt, mask
|
||||
from lembas.services.llm.openai_client import Endpoint, LLMError, list_models
|
||||
from lembas.web.templating import render
|
||||
@@ -39,7 +40,43 @@ def _connections(db: DBSession) -> list[Connection]:
|
||||
|
||||
@router.get("")
|
||||
async def admin_home(user: AdminUser):
|
||||
return RedirectResponse("/admin/connections", status_code=status.HTTP_303_SEE_OTHER)
|
||||
return RedirectResponse("/admin/general", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
@router.get("/general")
|
||||
async def general_page(request: Request, db: Db, user: AdminUser, saved: bool = False):
|
||||
return render(
|
||||
request,
|
||||
"admin/general.html",
|
||||
{
|
||||
"values": settings_store.get_group(db),
|
||||
"saved": saved,
|
||||
"user_count": db.scalar(select(func.count()).select_from(User)),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@router.post("/general")
|
||||
async def save_general(
|
||||
db: Db,
|
||||
user: AdminUser,
|
||||
instance_name: str = Form("LLeMbas"),
|
||||
allow_signup: bool = Form(False),
|
||||
) -> Response:
|
||||
"""Save instance settings.
|
||||
|
||||
Unchecked checkboxes are simply absent from a form post, which is why
|
||||
allow_signup defaults to False here -- that absence *is* the "off" signal.
|
||||
"""
|
||||
settings_store.update(
|
||||
db,
|
||||
{
|
||||
"instance_name": instance_name.strip()[:120] or "LLeMbas",
|
||||
"allow_signup": allow_signup,
|
||||
},
|
||||
)
|
||||
log.info("registration %s by %s", "opened" if allow_signup else "closed", user.email)
|
||||
return RedirectResponse("/admin/general?saved=1", status_code=status.HTTP_303_SEE_OTHER)
|
||||
|
||||
|
||||
@router.get("/connections")
|
||||
|
||||
Reference in New Issue
Block a user