Skip to content

Commit

Permalink
add avatar_url in /login response and redirect /logout to pulpito-ng
Browse files Browse the repository at this point in the history
Signed-off-by: Vallari <[email protected]>
  • Loading branch information
VallariAg committed Aug 18, 2023
1 parent 3d237f1 commit 13bd9e1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ async def handle_callback(code: str, request: Request):
"access_token": token,
}
request.session["user"] = data
cookie_data = {"username": data["username"]}
cookie_data = {
"username": data["username"],
"avatar_url": response_org_dic.get("user", {}).get("avatar_url"),
}
cookie = "; ".join(
[f"{str(key)}={str(value)}" for key, value in cookie_data.items()]
)
Expand Down
7 changes: 5 additions & 2 deletions src/routes/logout.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
import logging, os
from fastapi import APIRouter, HTTPException, Request
from fastapi.responses import RedirectResponse

PULPITO_URL = os.getenv("PULPITO_URL")
log = logging.getLogger(__name__)

router = APIRouter(
prefix="/logout",
tags=["logout"],
Expand All @@ -17,7 +20,7 @@ def logout(request: Request):
user = request.session.get("user")
if user:
request.session.pop("user", None)
return {"logout": "success"}
return RedirectResponse(PULPITO_URL)
log.warning("No session found, probably already logged out.")
raise HTTPException(
status_code=204, detail="No session found, probably already logged out."
Expand Down

0 comments on commit 13bd9e1

Please sign in to comment.