File size: 833 Bytes
ffd8e4f
 
 
 
 
ebc3c4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffd8e4f
 
 
fcfe4b3
ebc3c4f
ffd8e4f
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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