ramanjitsingh1368's picture
refactor user model and schemas to consolidate name fields and remove signup schema
fcfe4b3
raw
history blame contribute delete
833 Bytes
from typing_extensions import Annotated
from pydantic import BaseModel, AfterValidator
import re
class Validators:
@staticmethod
def validate_email(email: str) -> str:
"""Manual email validation using regex."""
email_regex = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
if not re.match(email_regex, email):
raise ValueError("Invalid email format.")
return email
@staticmethod
def validate_password(password: str) -> str:
"""Password validation."""
if len(password) < 8:
raise ValueError("Password must be at least 8 characters long.")
return password
class UserSignInSchema(BaseModel):
name: str
email: Annotated[str, AfterValidator(Validators.validate_email)]
class UserSignInResponse(BaseModel):
user_id: str