import hmac from fastapi import FastAPI, Form from fastapi.responses import HTMLResponse, RedirectResponse from app import auth from app.config import get_settings from app.routers import accounts, categories, transactions app = FastAPI(title="Finanzberatungs-Tool") app.include_router(accounts.router) app.include_router(transactions.router) app.include_router(categories.router) @app.get("/login", response_class=HTMLResponse) def login_form(): return """
""" @app.post("/login") def login(username: str = Form(...), password: str = Form(...)): s = get_settings() if not (hmac.compare_digest(username, s.gui_user) and auth.verify_password(password, s.gui_password_hash)): return HTMLResponse("Login fehlgeschlagen", status_code=401) resp = RedirectResponse("/", status_code=303) resp.set_cookie(auth.COOKIE, auth.make_session_token(), httponly=True, max_age=auth.MAX_AGE, samesite="lax") return resp @app.post("/logout") def logout(): resp = RedirectResponse("/login", status_code=303) resp.delete_cookie(auth.COOKIE) return resp