48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, EmailStr, Field, validator
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
username: str
|
|
full_name: Optional[str] = None
|
|
is_active: bool = True
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8)
|
|
password_confirm: str
|
|
|
|
@validator("password_confirm")
|
|
def passwords_match(cls, v, values, **kwargs):
|
|
if "password" in values and v != values["password"]:
|
|
raise ValueError("Passwords do not match")
|
|
return v
|
|
|
|
|
|
class UserUpdate(UserBase):
|
|
password: Optional[str] = None
|
|
is_active: Optional[bool] = None
|
|
is_superuser: Optional[bool] = None
|
|
|
|
|
|
class UserInDBBase(UserBase):
|
|
id: int
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
is_superuser: bool
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class UserRead(UserInDBBase):
|
|
"""Return schema for user without sensitive data"""
|
|
pass
|
|
|
|
|
|
class UserInDB(UserInDBBase):
|
|
"""Database schema for user including sensitive data"""
|
|
hashed_password: str |