Spaces:
Runtime error
Runtime error
| from typing_extensions import Annotated | |
| from pydantic import BaseModel, AfterValidator | |
| import re | |
| class Validators: | |
| 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 | |
| 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 | |