3a1da1482c
- FastAPI + SQLite + Alpine.js + HTMX PWA for Bingo Bango Bongo golf scoring - Passwordless magic link auth with email (aiosmtplib) and admin invite system - Real-time score entry via WebSocket with drag-and-drop player ordering - Course management with per-hole par and stroke index - Scorecard with golf score markers (birdie, eagle, bogey, etc.) - Two-step new game form with tee selection per player - Dashboard with stats, live games social stream, and recent game history - Game summary view (read-only scorecard with leaderboard) - User profile pages with win stats - PWA install support with generated PNG icons - Admin panel for users, courses, games, and invitations Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
from fastapi import APIRouter, Depends, Form, Request, UploadFile, File
|
|
from fastapi.responses import HTMLResponse
|
|
import aiosqlite
|
|
|
|
from app.database import get_db
|
|
from app.dependencies import get_current_user
|
|
from app.routers.onboarding import AVATARS
|
|
from app.templates_config import templates
|
|
from app.avatar import save_avatar
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/profile", response_class=HTMLResponse)
|
|
async def profile_page(request: Request, user: dict = Depends(get_current_user)):
|
|
return templates.TemplateResponse(
|
|
"profile/profile.html", {"request": request, "user": user, "avatars": AVATARS}
|
|
)
|
|
|
|
|
|
@router.post("/profile", response_class=HTMLResponse)
|
|
async def profile_submit(
|
|
request: Request,
|
|
name: str = Form(...),
|
|
handicap: float = Form(...),
|
|
avatar_emoji: str = Form(""),
|
|
avatar_file: UploadFile = File(None),
|
|
user: dict = Depends(get_current_user),
|
|
db: aiosqlite.Connection = Depends(get_db),
|
|
):
|
|
errors = {}
|
|
name = name.strip()
|
|
if not name:
|
|
errors["name"] = "Name is required."
|
|
if not (0.0 <= handicap <= 54.0):
|
|
errors["handicap"] = "Handicap must be between 0 and 54."
|
|
|
|
avatar = user["avatar"] # keep existing if nothing new provided
|
|
if avatar_file and avatar_file.filename:
|
|
avatar, err = await save_avatar(avatar_file, user["id"])
|
|
if err:
|
|
errors["avatar"] = err
|
|
elif avatar_emoji in AVATARS:
|
|
avatar = avatar_emoji
|
|
|
|
if errors:
|
|
return templates.TemplateResponse(
|
|
"profile/profile.html",
|
|
{"request": request, "user": user, "avatars": AVATARS, "errors": errors},
|
|
)
|
|
|
|
await db.execute(
|
|
"UPDATE users SET name = ?, handicap = ?, avatar = ? WHERE id = ?",
|
|
(name, handicap, avatar, user["id"]),
|
|
)
|
|
await db.commit()
|
|
|
|
return templates.TemplateResponse(
|
|
"profile/profile.html",
|
|
{"request": request, "user": {**user, "name": name, "handicap": handicap, "avatar": avatar},
|
|
"avatars": AVATARS, "success": "Profile updated."},
|
|
)
|