""" Pydantic schemas for authentication and token exchange. """ from typing import Optional from uuid import UUID from pydantic import BaseModel, EmailStr, field_validator import re class Token(BaseModel): access_token: str refresh_token: str token_type: str = "bearer" class TokenRefreshRequest(BaseModel): refresh_token: str class CustomOAuth2PasswordRequestForm(BaseModel): """Used for custom JSON login if not using standard OAuth2 form encoding.""" email: EmailStr password: str class UserRegister(BaseModel): """Schema for registering a new user & workspace (if first user).""" email: EmailStr password: str full_name: str # If workspace_id is omitted, they create a new workspace workspace_name: Optional[str] = None workspace_id: Optional[UUID] = None @field_validator("password") @classmethod def validate_password_complexity(cls, v: str) -> str: if len(v) < 8: raise ValueError("Password must be at least 8 characters long.") if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): raise ValueError("Password must contain at least one digit or special character.") return v class PasswordChangeRequest(BaseModel): old_password: str new_password: str @field_validator("new_password") @classmethod def validate_new_password_complexity(cls, v: str) -> str: if len(v) < 8: raise ValueError("Password must be at least 8 characters long.") if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): raise ValueError("Password must contain at least one digit or special character.") return v class ForgotPasswordRequest(BaseModel): email: EmailStr class ResetPasswordRequest(BaseModel): token: str new_password: str @field_validator("new_password") @classmethod def validate_reset_password_complexity(cls, v: str) -> str: if len(v) < 8: raise ValueError("Password must be at least 8 characters long.") if not re.search(r"[0-9!@#$%^&*(),.?\":{}|<>]", v): raise ValueError("Password must contain at least one digit or special character.") return v class TokenRefreshResponse(BaseModel): access_token: str token_type: str = "bearer"