(20241127) GMail work updated.

This commit is contained in:
2024-11-27 20:13:25 +05:30
parent 7b08e37d2f
commit 269e36ec27
11 changed files with 532 additions and 1 deletions
View File
View File
+128
View File
@@ -0,0 +1,128 @@
"""
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
View File
+108
View File
@@ -0,0 +1,108 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Wednesday, 27th Nov., 2024.
OBJECTIVE:
To provide the structure for the request and response of the APIs that will be used to request OAuth2.0
authorization for mail services.
REFERENCES:
N/A
DOWNLOADS:
N/A
"""
# *****************************************************************************************************************
# ***** ****
# *** IMPORT ***
# ***** ****
# *****************************************************************************************************************
# To make sibling directories accessible for imports:
import sys
sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator
from typing import Optional, Literal
# My utils:
from utils_v2.string import regex
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class LoginRequest(BaseModel):
username: str = Field(description = "the username of the user")
password: str = Field(description = "the password of the user")
mode: Optional[str] = Field(
description = "the mode through which this request came in",
default = "N/A"
)
remoteIp: Optional[str] = Field(
description = "the ip addr of the client",
default = "N/A"
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass