Files
bakery-ia/services/auth/app/schemas/auth.py
2025-07-19 17:49:03 +02:00

79 lines
2.2 KiB
Python

# services/auth/app/schemas/auth.py
"""
Authentication schemas
"""
from pydantic import BaseModel, EmailStr, Field, validator
from typing import Optional
from datetime import datetime
class UserRegistration(BaseModel):
"""User registration schema"""
email: EmailStr
password: str = Field(..., min_length=8)
full_name: str = Field(..., min_length=2, max_length=100)
phone: Optional[str] = None
language: str = Field(default="es", pattern="^(es|en)$")
@validator('password')
def validate_password(cls, v):
"""Basic password validation"""
if len(v) < 8:
raise ValueError('Password must be at least 8 characters')
if not any(c.isupper() for c in v):
raise ValueError('Password must contain uppercase letter')
if not any(c.islower() for c in v):
raise ValueError('Password must contain lowercase letter')
if not any(c.isdigit() for c in v):
raise ValueError('Password must contain number')
return v
class UserLogin(BaseModel):
"""User login schema"""
email: EmailStr
password: str
class TokenResponse(BaseModel):
"""Token response schema"""
access_token: str
refresh_token: str
token_type: str = "bearer"
expires_in: int
class RefreshTokenRequest(BaseModel):
"""Refresh token request schema"""
refresh_token: str
class UserResponse(BaseModel):
"""User response schema"""
id: str
email: str
full_name: str
is_active: bool
is_verified: bool
phone: Optional[str]
language: str
created_at: datetime
last_login: Optional[datetime]
class Config:
from_attributes = True
class PasswordChangeRequest(BaseModel):
"""Password change request schema"""
current_password: str
new_password: str = Field(..., min_length=8)
@validator('new_password')
def validate_new_password(cls, v):
"""Validate new password strength"""
if len(v) < 8:
raise ValueError('Password must be at least 8 characters')
return v
class TokenVerificationResponse(BaseModel):
"""Token verification response for other services"""
user_id: str
email: str
is_active: bool
expires_at: datetime