Add first info to landing page

This commit is contained in:
2025-10-23 12:35:52 +02:00
parent f6e69b1521
commit 81929cca21
11 changed files with 186 additions and 57 deletions

View File

@@ -4,12 +4,18 @@ from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from sqlalchemy.orm import Session
from allmende_payment_system.database import SessionLocal, ensure_user
async def get_user(request: Request) -> dict:
if username := os.environ.get("APS_username", None):
return {"username": username}
return {
"username": username,
"display_name": os.environ.get("APS_display_name", "Missing Display Name"),
}
if "ynh_user" not in request.headers:
raise HTTPException(status_code=401, detail="Missing ynh_user header")
return {"username": request.headers["ynh_user"]}
@@ -28,6 +34,21 @@ app.mount(
)
def get_session() -> Session:
db = SessionLocal()
try:
yield db
finally:
db.close()
SessionDep = Annotated[Session, Depends(get_session)]
@app.get("/")
async def landing_page(request: Request):
return templates.TemplateResponse("index.html.jinja", {"request": request})
async def landing_page(request: Request, user_info: UserDep, session: SessionDep):
user = ensure_user(user_info, session)
print(f"User {user.username} ({user.display_name}) accessed landing page")
return templates.TemplateResponse(
"index.html.jinja", context={"request": request, "user": user}
)