From 2d22158dd95f76399f5716d556be60c77da04a46 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 30 Jul 2026 16:03:32 +0200 Subject: Admin ui --- authentication/endpoints.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'authentication/endpoints.py') diff --git a/authentication/endpoints.py b/authentication/endpoints.py index 6877383..3af49fc 100644 --- a/authentication/endpoints.py +++ b/authentication/endpoints.py @@ -6,6 +6,7 @@ from uuid import uuid7 from fastapi import FastAPI, Request, Form, Query from pydantic import BaseModel, ValidationError, model_validator, EmailStr +from sqlalchemy import func from sqlmodel import select from starlette.authentication import requires from starlette.middleware.authentication import AuthenticationMiddleware @@ -106,10 +107,17 @@ class RegisterForm(BaseModel): return self +def is_first_run() -> bool: + with get_session_context() as session: + user_count = session.exec(select(func.count(User.id))) + return user_count.first() == 0 + + async def base_register(request: Request, form: RegisterForm | None = None, errors: dict[str, str] | None = None): return templates.TemplateResponse(request, 'register.html', context={ 'form': form, 'errors': errors, + 'is_first_run': is_first_run(), }) @@ -145,7 +153,7 @@ async def post_register(request: Request, email: Annotated[str, Form()] = '', pa return RedirectResponse(next, status_code=303) except ValidationError as exc: - errors.update({e['loc'][0]: e['msg'] for e in exc.errors()}) + errors.update({(e['loc'][0] if e['loc'] else 'verify_password'): e['msg'] for e in exc.errors()}) return await base_register(request, form, errors) -- cgit v1.2.3