File size: 1,566 Bytes
345855e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pydantic import BaseModel, EmailStr, Field, ConfigDict


# =========================================================
# BASE CONFIG (STRICT MODE → PREVENTS SILENT DATA COERCION)
# =========================================================
class StrictSchema(BaseModel):
    model_config = ConfigDict(
        strict=True,
        extra="forbid",
        validate_assignment=True,
    )


# =========================================================
# SIGNUP SCHEMA
# =========================================================
class SignupSchema(StrictSchema):
    email: EmailStr
    username: str = Field(
        min_length=3,
        max_length=32,
        pattern=r"^[a-zA-Z0-9_]+$"
    )
    password: str = Field(
        min_length=8,
        max_length=72,
    )


# =========================================================
# LOGIN SCHEMA
# =========================================================
class LoginSchema(StrictSchema):
    email: EmailStr
    password: str = Field(
        min_length=1,
        max_length=72,
    )


# =========================================================
# TOKEN REQUEST SCHEMA
# =========================================================
class TokenSchema(StrictSchema):
    token: str = Field(
        min_length=10,
        max_length=2048
    )


# =========================================================
# USER RESPONSE SCHEMA (SAFE OUTPUT MODEL)
# =========================================================
class UserOutSchema(StrictSchema):
    id: int
    email: EmailStr
    username: str
    created_at: str