Files
api_utils_converse_v2/models/behaviour/mail/oauth.py
T

129 lines
5.4 KiB
Python

"""
AUTHOR:
Khushal P Soonderji
DATE:
Thursday, 24th Oct., 2024
OBJECTIVE:
To define the interaction between the UI layer and the database connectivity in one place. Here we will handle
all user-related interactions.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# The base model:
from models.behaviour.base import BaseModel
# My async utils:
from utils_v2.string import json
from utils_v2.cache.async_redis_cache_v2 import AsyncRedisCache
from utils_v2.database.async_mysql_v2 import AsyncMySQL
# The data models:
from models.data.user.user import (
IsSessionRequest
)
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** CLASSES ***
# ***** ****
# *****************************************************************************************************************
class UserModel(BaseModel):
async def is_session(
self,
db_conn: AsyncMySQL,
request: IsSessionRequest,
cache: AsyncRedisCache,
cache_expiry: int = 3_600
):
"""
Fetches information about the current user from his session.
:param db_conn: The database connection to use to perform the action.
:param request: The instance of the data model that defines the structure of the request.
:param cache: The caching object to use to set the session in cache memory.
:param cache_expiry: The no. of seconds after which this information will be deleted from the cache.
:return: The raw response from the database call (SQL).
"""
return await self.call_cached_procedure(
cache = cache,
cache_key = "usr_is_" + str(request.sessionToken),
cache_expiry = cache_expiry,
db_conn = db_conn,
proc_name = "isSession",
proc_args = (request.sessionToken,),
session_token = request.sessionToken
)
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass