Improve auth flow
This commit is contained in:
@@ -1,35 +1,31 @@
|
||||
# services/auth/app/schemas/auth.py
|
||||
"""
|
||||
Authentication schemas
|
||||
Authentication schemas
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field, validator
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
from app.core.config import settings
|
||||
from shared.utils.validation import validate_spanish_phone
|
||||
|
||||
class UserRegistration(BaseModel):
|
||||
"""User registration schema"""
|
||||
email: EmailStr
|
||||
password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH)
|
||||
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):
|
||||
"""Validate password strength"""
|
||||
from app.core.security import security_manager
|
||||
if not security_manager.validate_password(v):
|
||||
raise ValueError('Password does not meet security requirements')
|
||||
return v
|
||||
|
||||
@validator('phone')
|
||||
def validate_phone(cls, v):
|
||||
"""Validate phone number"""
|
||||
if v and not validate_spanish_phone(v):
|
||||
raise ValueError('Invalid Spanish phone number')
|
||||
"""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):
|
||||
@@ -55,55 +51,29 @@ class UserResponse(BaseModel):
|
||||
full_name: str
|
||||
is_active: bool
|
||||
is_verified: bool
|
||||
tenant_id: Optional[str]
|
||||
role: str
|
||||
phone: Optional[str]
|
||||
language: str
|
||||
timezone: str
|
||||
created_at: Optional[datetime]
|
||||
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=settings.PASSWORD_MIN_LENGTH)
|
||||
new_password: str = Field(..., min_length=8)
|
||||
|
||||
@validator('new_password')
|
||||
def validate_new_password(cls, v):
|
||||
"""Validate new password strength"""
|
||||
from app.core.security import security_manager
|
||||
if not security_manager.validate_password(v):
|
||||
raise ValueError('New password does not meet security requirements')
|
||||
if len(v) < 8:
|
||||
raise ValueError('Password must be at least 8 characters')
|
||||
return v
|
||||
|
||||
class PasswordResetRequest(BaseModel):
|
||||
"""Password reset request schema"""
|
||||
email: EmailStr
|
||||
|
||||
class PasswordResetConfirm(BaseModel):
|
||||
"""Password reset confirmation schema"""
|
||||
token: str
|
||||
new_password: str = Field(..., min_length=settings.PASSWORD_MIN_LENGTH)
|
||||
|
||||
@validator('new_password')
|
||||
def validate_new_password(cls, v):
|
||||
"""Validate new password strength"""
|
||||
from app.core.security import security_manager
|
||||
if not security_manager.validate_password(v):
|
||||
raise ValueError('New password does not meet security requirements')
|
||||
return v
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
"""User update schema"""
|
||||
full_name: Optional[str] = Field(None, min_length=2, max_length=100)
|
||||
phone: Optional[str] = None
|
||||
language: Optional[str] = Field(None, pattern="^(es|en)$")
|
||||
timezone: Optional[str] = None
|
||||
tenant_id: Optional[str] = None
|
||||
|
||||
@validator('phone')
|
||||
def validate_phone(cls, v):
|
||||
"""Validate phone number"""
|
||||
if v and not validate_spanish_phone(v):
|
||||
raise ValueError('Invalid Spanish phone number')
|
||||
return v
|
||||
class TokenVerificationResponse(BaseModel):
|
||||
"""Token verification response for other services"""
|
||||
user_id: str
|
||||
email: str
|
||||
is_active: bool
|
||||
expires_at: datetime
|
||||
@@ -17,3 +17,5 @@ python-json-logger==2.0.4
|
||||
pytz==2023.3
|
||||
python-logstash==0.4.8
|
||||
structlog==23.2.0
|
||||
python-dotenv==1.0.0
|
||||
|
||||
Reference in New Issue
Block a user