Files

125 lines
5.0 KiB
Python

"""
AUTHOR:
Khushal P Soonderji
DATE:
Wednesday, 27th Nov., 2024
OBJECTIVE:
To get the session information from the session token for a given user.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# To use Quart:
from quart import current_app
# The data model:
from models.core.user import CoreUserInfoModel
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** CLASSES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
async def get_session(session_token) -> CoreUserInfoModel:
"""
Gets the session's info from the session token.
:param session_token: The identifier of the session.
:return: The info or None.
"""
try:
# Fetch the raw info from cache:
raw_info = await current_app.module_cache.get(key = session_token)
# Feed needed field into the core model:
session_info = CoreUserInfoModel(
fullName = raw_info["full_name"],
role = raw_info["user_role"],
userId = raw_info["user_id"],
entityId = raw_info["entity_id"],
billingAccountId = raw_info["billing_account_id"],
departmentId = raw_info["department_id"],
branchId = raw_info["branch_id"],
industry = raw_info["industry"]
)
# Done here:
return session_info
# In case something goes wrong:
except Exception as exception:
current_app.printer(exception)
return None
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass