Automated Action 4e361e2d61 Add user authentication and user-specific invoice management
- Create User model and database schema
- Add JWT authentication with secure password hashing
- Create authentication endpoints for registration and login
- Update invoice routes to require authentication
- Ensure users can only access their own invoices
- Update documentation in README.md
2025-05-30 09:00:26 +00:00

67 lines
1.4 KiB
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, EmailStr, Field, validator
class UserBase(BaseModel):
"""
Base user schema with shared attributes
"""
email: EmailStr
username: str
is_active: Optional[bool] = True
full_name: Optional[str] = None
class UserCreate(UserBase):
"""
User creation schema
"""
password: str = Field(..., min_length=8)
@validator("password")
def password_strength(cls, v):
"""
Validate password strength
"""
if len(v) < 8:
raise ValueError("Password must be at least 8 characters long")
return v
class UserUpdate(BaseModel):
"""
User update schema
"""
email: Optional[EmailStr] = None
full_name: Optional[str] = None
password: Optional[str] = None
@validator("password")
def password_strength(cls, v):
"""
Validate password strength if provided
"""
if v is not None and len(v) < 8:
raise ValueError("Password must be at least 8 characters long")
return v
class UserInDB(UserBase):
"""
User schema as stored in the database
"""
id: int
created_at: datetime
updated_at: datetime
class Config:
from_attributes = True
class User(UserInDB):
"""
User schema for API responses
"""
pass