mirror of
https://github.com/TronoSfera/backup_service.git
synced 2026-05-18 10:03:32 +03:00
Merge pull request #12 from TronoSfera/codex/fix-redirect-after-successful-server-login
Redirect authenticated admins from login page and set login cookie path/expiry
This commit is contained in:
commit
69a60f8b31
1 changed files with 14 additions and 1 deletions
|
|
@ -690,7 +690,18 @@ async def update_client_config(
|
||||||
# ======== Web interface routes =========
|
# ======== Web interface routes =========
|
||||||
|
|
||||||
@app.get("/login", response_class=HTMLResponse)
|
@app.get("/login", response_class=HTMLResponse)
|
||||||
async def login_page(request: Request) -> Response:
|
async def login_page(
|
||||||
|
request: Request,
|
||||||
|
db: Session = Depends(database.get_db),
|
||||||
|
) -> Response:
|
||||||
|
raw_token = request.cookies.get("access_token")
|
||||||
|
if raw_token:
|
||||||
|
try:
|
||||||
|
current_user = await auth.get_current_user(request=request, token=None, db=db)
|
||||||
|
except HTTPException:
|
||||||
|
current_user = None
|
||||||
|
if current_user and current_user.is_admin:
|
||||||
|
return RedirectResponse(url="/clients", status_code=status.HTTP_303_SEE_OTHER)
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"login.html",
|
"login.html",
|
||||||
{
|
{
|
||||||
|
|
@ -725,6 +736,8 @@ async def login_submit(
|
||||||
access_token,
|
access_token,
|
||||||
httponly=True,
|
httponly=True,
|
||||||
samesite="lax",
|
samesite="lax",
|
||||||
|
path="/",
|
||||||
|
max_age=auth.ACCESS_TOKEN_EXPIRE_MINUTES * 60,
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue