diff options
author | Frederick Muriuki Muriithi | 2025-04-05 09:17:35 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-04-05 09:21:08 -0500 |
commit | d84a0acd6f80267de20575966149d074f10ad862 (patch) | |
tree | 44ff9d1bd1fc0f46746d5c743486bbc0c6b5e3e4 /uploader/oauth2/client.py | |
parent | 2377c56b6edfb47431be70d6a64586ecc673be88 (diff) | |
download | gn-uploader-d84a0acd6f80267de20575966149d074f10ad862.tar.gz |
Fix fetching of user details.
Move the fetching of user details to the client module. Add checks to
only fetch the details if they are not updated yet.
Diffstat (limited to 'uploader/oauth2/client.py')
-rw-r--r-- | uploader/oauth2/client.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/uploader/oauth2/client.py b/uploader/oauth2/client.py index 1efa299..12fbf80 100644 --- a/uploader/oauth2/client.py +++ b/uploader/oauth2/client.py @@ -1,6 +1,7 @@ """OAuth2 client utilities.""" import json import time +import uuid import random from datetime import datetime, timedelta from urllib.parse import urljoin, urlparse @@ -146,9 +147,24 @@ def oauth2_client(): __client__) +def fetch_user_details() -> Either: + """Retrieve user details from the auth server""" + suser = session.session_info()["user"] + if suser["email"] == "anon@ymous.user": + udets = oauth2_get("auth/user/").then( + lambda usrdets: session.set_user_details({ + "user_id": uuid.UUID(usrdets["user_id"]), + "name": usrdets["name"], + "email": usrdets["email"], + "token": session.user_token()})) + return udets + return Right(suser) + + def user_logged_in(): """Check whether the user has logged in.""" suser = session.session_info()["user"] + fetch_user_details() return suser["logged_in"] and suser["token"].is_right() |