(20250220) Bug fix in reminders for work.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user