~tsileo/microblog.pub

e454e8fe843ce2309ef7a16d0f8a7d1ca8600958 — Thomas Sileo 2 months ago f7671f0
Tweak admin login logic
1 files changed, 8 insertions(+), 12 deletions(-)

M app/admin.py
M app/admin.py => app/admin.py +8 -12
@@ 34,6 34,7 @@ from app.config import verify_password
from app.database import AsyncSession
from app.database import get_db_session
from app.lookup import lookup
from app.templates import is_current_user_admin
from app.uploads import save_upload
from app.utils import pagination
from app.utils.emoji import EMOJIS_BY_NAME


@@ 68,16 69,6 @@ router = APIRouter(
unauthenticated_router = APIRouter()


@router.get("/")
async def admin_index(
    request: Request,
    db_session: AsyncSession = Depends(get_db_session),
) -> templates.TemplateResponse:
    return await templates.render_template(
        db_session, request, "index.html", {"request": request}
    )


@router.get("/lookup")
async def get_lookup(
    request: Request,


@@ 1108,7 1099,10 @@ async def admin_actions_vote(
async def login(
    request: Request,
    db_session: AsyncSession = Depends(get_db_session),
) -> templates.TemplateResponse:
) -> templates.TemplateResponse | RedirectResponse:
    if is_current_user_admin(request):
        return RedirectResponse(request.url_for("admin_stream"), status_code=302)

    return await templates.render_template(
        db_session,
        request,


@@ 1142,7 1136,9 @@ async def login_validation(
            status_code=403,
        )

    resp = RedirectResponse(redirect or "/admin/stream", status_code=302)
    resp = RedirectResponse(
        redirect or request.url_for("admin_stream"), status_code=302
    )
    resp.set_cookie("session", session_serializer.dumps({"is_logged_in": True}))  # type: ignore  # noqa: E501

    return resp