(20250619) Shifted the timed OTP generation code to this project.

This commit is contained in:
2025-06-19 16:41:51 +05:30
parent c754bb6a97
commit 265705a7da
7 changed files with 481 additions and 13 deletions
View File
+121
View File
@@ -0,0 +1,121 @@
"""
AUTHOR:
Khushal P Soonderji
DATE:
Tuesday, 10th Sept., 2024.
OBJECTIVE:
To provide a data structure for the JSON received in the API calls to generate and verify timed OTPs.
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 models:
from pydantic import BaseModel, Field, field_validator, Extra
from typing import Optional, Any, Dict, List
from typing_extensions import Annotated
# My utils:
from utils_v2.string import regex
# *****************************************************************************************************************
# ***** ****
# *** MACROS / ONE-TIME INIT ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** VARIABLES ***
# ***** ****
# *****************************************************************************************************************
# --- Nothing Yet
# *****************************************************************************************************************
# ***** ****
# *** FUNCTIONS ***
# ***** ****
# *****************************************************************************************************************
class GenerateTimedOTP(BaseModel):
id: str | Dict | List
attempts: Optional[int] = 3
seconds: Optional[int | float] = 30.0
class Config:
extra = "forbid"
def get(self, key: str, default = None):
return getattr(self, key, default)
@field_validator("attempts")
def validate_attempts(cls, value):
if not 1 <= value <= 10: raise ValueError("attempts must be at least 1 and at most 10")
return value
@field_validator("seconds")
def validate_expiry(cls, value):
if not 30 <= value <= 300: raise ValueError("expiry must be at least 30s and at most 300s")
return value
# ---------------------------------------------------------------------------------------------------------------------
class VerifyTimedOTP(BaseModel):
id: str | Dict | List
otp: str
class Config:
extra = "forbid"
def get(self, key: str, default = None):
return getattr(self, key, default)
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass