Files
LMS/backend/app/schemas.py
T

48 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from datetime import datetime
from pydantic import BaseModel, EmailStr, field_validator
import re
# ── Auth ─────────────────────────────────────────────────────────────────────
class UserRegister(BaseModel):
username: str
email: EmailStr
password: str
@field_validator("username")
@classmethod
def username_valid(cls, v: str) -> str:
v = v.strip()
if not re.match(r"^[A-Za-z0-9_]{3,64}$", v):
raise ValueError(
"Username must be 364 characters, letters/numbers/underscore only."
)
return v
@field_validator("password")
@classmethod
def password_strength(cls, v: str) -> str:
if len(v) < 8:
raise ValueError("Password must be at least 8 characters.")
return v
class UserLogin(BaseModel):
username: str
password: str
class UserOut(BaseModel):
id: int
username: str
email: str
created_at: datetime
model_config = {"from_attributes": True}
class TokenPayload(BaseModel):
sub: int # user id
exp: int