124 lines
5.1 KiB
Python
124 lines
5.1 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.data.core.user_info import CoreUserInfoModel
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MACROS / ONE-TIME INIT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** VARIABLES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** CLASSES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** FUNCTIONS ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
async def get_session(session_token):
|
|
|
|
"""
|
|
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["value"]["full_name"],
|
|
userId = raw_info["value"]["user_id"],
|
|
entityId = raw_info["value"]["entity_id"],
|
|
billingAccountId = raw_info["value"]["billing_account_id"],
|
|
departmentId = raw_info["value"]["department_id"],
|
|
branchId = raw_info["value"]["branch_id"],
|
|
industry = raw_info["value"]["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
|