feat(auth): create registration route and integrate with AuthService feat(auth): implement user registration logic in AuthService with Keycloak integration fix(config): add Keycloak admin credentials to settings fix(middleware): update tenant middleware to include new auth routes chore(docs): remove outdated testing guide and add project architecture documentation feat(frontend): implement user registration page and integrate with API feat(frontend): create login page with tenant selection and error handling refactor(frontend): update layout to use custom auth store and improve loading states
112 lines
3.4 KiB
Python
112 lines
3.4 KiB
Python
"""
|
|
DTOs para módulo de autenticación
|
|
"""
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
from typing import Optional
|
|
|
|
|
|
class LoginRequestDTO(BaseModel):
|
|
"""DTO para solicitud de login"""
|
|
username: str = Field(..., description="Usuario o email")
|
|
password: str = Field(..., min_length=6, description="Contraseña")
|
|
tenant_slug: str = Field(..., description="Slug del tenant")
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"username": "usuario@ejemplo.com",
|
|
"password": "password123",
|
|
"tenant_slug": "empresa-abc"
|
|
}
|
|
}
|
|
|
|
|
|
class TokenResponseDTO(BaseModel):
|
|
"""DTO para respuesta de token"""
|
|
access_token: str
|
|
refresh_token: str
|
|
token_type: str = "bearer"
|
|
expires_in: int
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
|
|
"token_type": "bearer",
|
|
"expires_in": 3600
|
|
}
|
|
}
|
|
|
|
|
|
class RefreshTokenRequestDTO(BaseModel):
|
|
"""DTO para solicitud de refresh token"""
|
|
refresh_token: str = Field(..., description="Refresh token")
|
|
|
|
|
|
class UserInfoResponseDTO(BaseModel):
|
|
"""DTO para información de usuario"""
|
|
sub: str
|
|
email: Optional[str] = None
|
|
name: Optional[str] = None
|
|
preferred_username: Optional[str] = None
|
|
tenant_id: Optional[int] = None
|
|
roles: list[str] = []
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"sub": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
"email": "usuario@ejemplo.com",
|
|
"name": "Juan Pérez",
|
|
"preferred_username": "jperez",
|
|
"tenant_id": 1,
|
|
"roles": ["user", "admin"]
|
|
}
|
|
}
|
|
|
|
|
|
class LogoutRequestDTO(BaseModel):
|
|
"""DTO para solicitud de logout"""
|
|
refresh_token: str = Field(..., description="Refresh token para invalidar")
|
|
|
|
|
|
class RegisterRequestDTO(BaseModel):
|
|
"""DTO para solicitud de registro"""
|
|
username: str = Field(..., min_length=3, max_length=50, description="Nombre de usuario")
|
|
email: EmailStr = Field(..., description="Email del usuario")
|
|
password: str = Field(..., min_length=8, description="Contraseña")
|
|
first_name: str = Field(..., min_length=2, max_length=50, description="Nombre")
|
|
last_name: str = Field(..., min_length=2, max_length=50, description="Apellido")
|
|
tenant_slug: str = Field(..., description="Slug del tenant")
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"username": "jperez",
|
|
"email": "jperez@ejemplo.com",
|
|
"password": "MiPassword123!",
|
|
"first_name": "Juan",
|
|
"last_name": "Pérez",
|
|
"tenant_slug": "empresa-abc"
|
|
}
|
|
}
|
|
|
|
|
|
class RegisterResponseDTO(BaseModel):
|
|
"""DTO para respuesta de registro"""
|
|
user_id: str
|
|
username: str
|
|
email: str
|
|
message: str
|
|
|
|
class Config:
|
|
json_schema_extra = {
|
|
"example": {
|
|
"user_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
|
|
"username": "jperez",
|
|
"email": "jperez@ejemplo.com",
|
|
"message": "User registered successfully"
|
|
}
|
|
}
|