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:
Jaroslav Beneš
2026-07-21 11:14:33 +02:00
parent dd9e0e9440
commit ba2fb1e13d
17 changed files with 727 additions and 153 deletions
+5 -1
View File
@@ -22,6 +22,10 @@
<nav class="sidebar__scroll" aria-label="Administration">
<div class="nav-group">
<div class="nav-group__label">Administration</div>
<a class="nav-item {{ 'is-active' if section == 'general' }}" href="/admin/general">
{{ icon("gear", "icon--sm") }}
<span class="nav-item__label">General</span>
</a>
<a class="nav-item {{ 'is-active' if section == 'connections' }}"
href="/admin/connections">
{{ icon("server", "icon--sm") }}
@@ -40,7 +44,7 @@
<span class="nav-item__label">Users &amp; groups</span>
</span>
<span class="nav-item is-disabled">
{{ icon("gear", "icon--sm") }}
{{ icon("sliders", "icon--sm") }}
<span class="nav-item__label">Tools</span>
</span>
</div>
@@ -0,0 +1,74 @@
{% extends "admin/_layout.html" %}
{% from "_macros.html" import icon %}
{% set section = "general" %}
{% block title %}General - LLeMbas{% endblock %}
{% block heading %}General{% endblock %}
{% block admin_content %}
<p class="admin-lede">
Instance-wide settings. These are stored in the database and take effect
immediately — no restart, and they survive one.
</p>
{% if saved %}
<div class="alert alert--success">{{ icon("check", "icon--sm") }} <span>Settings saved.</span></div>
{% endif %}
<form method="post" action="/admin/general">
<section class="card">
<h2 class="card__title">Identity</h2>
<div class="field">
<label class="field__label" for="instance-name">Instance name</label>
<input class="input" id="instance-name" name="instance_name"
value="{{ values.instance_name }}" maxlength="120">
<p class="field__hint">Shown in the browser tab and on the sign-in page.</p>
</div>
</section>
<section class="card">
<h2 class="card__title">
Registration
{% if values.allow_signup %}
<span class="badge badge--success">open</span>
{% else %}
<span class="badge badge--danger">closed</span>
{% endif %}
</h2>
<div class="field">
<label class="checkbox">
<input type="checkbox" name="allow_signup" value="true"
{{ 'checked' if values.allow_signup }}>
<span>Anyone who can reach this instance may create an account</span>
</label>
<p class="field__hint">
Turn this off once your users exist. Sign-in is unaffected — existing
accounts keep working, and the "Create one" link disappears from the
sign-in page.
</p>
</div>
{% if values.allow_signup and user_count > 0 %}
<div class="alert alert--warning">
{{ icon("warning", "alert__icon") }}
<div>
<strong>Registration is open.</strong>
<div class="text-sm" style="margin-top: var(--sp-1)">
This instance has {{ user_count }} account{{ '' if user_count == 1 else 's' }}.
Anyone who can reach it can add another, and every account can use your
configured models and API keys.
</div>
</div>
</div>
{% endif %}
<p class="field__hint">
<code>LEMBAS_ALLOW_SIGNUP</code> in the environment sets only the starting
value. Once saved here, this setting wins.
</p>
</section>
<button class="btn btn--primary" type="submit">Save settings</button>
</form>
{% endblock %}
+39
View File
@@ -21,6 +21,17 @@
<div class="admin-scroll">
<div class="admin-page">
{% if error %}
<div class="alert alert--error" role="alert">
{{ icon("warning", "alert__icon") }} <span>{{ error }}</span>
</div>
{% endif %}
{% if saved %}
<div class="alert alert--success" role="status">
{{ icon("check", "icon--sm") }} <span>{{ saved }}</span>
</div>
{% endif %}
<section class="card">
<h2 class="card__title">Account</h2>
<div class="field">
@@ -55,6 +66,34 @@
</p>
</section>
<section class="card">
<h2 class="card__title">Change password</h2>
<form method="post" action="/api/preferences/password">
<div class="field">
<label class="field__label" for="current-password">Current password</label>
<input class="input" type="password" id="current-password"
name="current_password" required autocomplete="current-password">
</div>
<div class="field">
<label class="field__label" for="new-password">New password</label>
<input class="input" type="password" id="new-password" name="new_password"
required minlength="8" autocomplete="new-password">
<p class="field__hint">At least 8 characters.</p>
</div>
<div class="field">
<label class="field__label" for="confirm-password">Confirm new password</label>
<input class="input" type="password" id="confirm-password"
name="confirm_password" required minlength="8"
autocomplete="new-password">
</div>
<button class="btn btn--primary" type="submit">Change password</button>
<p class="field__hint" style="margin-top: var(--sp-3)">
Every other session is signed out when the password changes. You
stay signed in here.
</p>
</form>
</section>
<section class="card">
<h2 class="card__title">Session</h2>
<form method="post" action="/auth/logout">