mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-14 18:58:10 +08:00
![dependabot-preview[bot]](/assets/img/avatar_default.png)
* Bump fastapi from 0.43.0 to 0.44.0 Bumps [fastapi](https://github.com/tiangolo/fastapi) from 0.43.0 to 0.44.0. - [Release notes](https://github.com/tiangolo/fastapi/releases) - [Changelog](https://github.com/tiangolo/fastapi/blob/master/docs/history-design-future.md) - [Commits](https://github.com/tiangolo/fastapi/compare/0.43.0...0.44.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> * Fix breaking changes and depreciation following fastapi 0.44.0 * Bump fastapi==0.44.0 in pyproject.toml
59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import uuid
|
|
from typing import Optional, Type
|
|
|
|
import pydantic
|
|
from pydantic import BaseModel, EmailStr
|
|
|
|
|
|
class BaseUser(BaseModel):
|
|
"""Base User model."""
|
|
|
|
id: Optional[str] = None
|
|
email: Optional[EmailStr] = None
|
|
is_active: Optional[bool] = True
|
|
is_superuser: Optional[bool] = False
|
|
|
|
@pydantic.validator("id", pre=True, always=True)
|
|
def default_id(cls, v):
|
|
return v or str(uuid.uuid4())
|
|
|
|
def create_update_dict(self):
|
|
return self.dict(
|
|
exclude_unset=True, exclude={"id", "is_superuser", "is_active"}
|
|
)
|
|
|
|
def create_update_dict_superuser(self):
|
|
return self.dict(exclude_unset=True, exclude={"id"})
|
|
|
|
|
|
class BaseUserCreate(BaseUser):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class BaseUserUpdate(BaseUser):
|
|
password: Optional[str]
|
|
|
|
|
|
class BaseUserDB(BaseUser):
|
|
hashed_password: str
|
|
|
|
|
|
class Models:
|
|
"""Generate models inheriting from the custom User model."""
|
|
|
|
def __init__(self, user_model: Type[BaseUser]):
|
|
class UserCreate(user_model, BaseUserCreate): # type: ignore
|
|
pass
|
|
|
|
class UserUpdate(user_model, BaseUserUpdate): # type: ignore
|
|
pass
|
|
|
|
class UserDB(user_model, BaseUserDB): # type: ignore
|
|
pass
|
|
|
|
self.User = user_model
|
|
self.UserCreate = UserCreate
|
|
self.UserUpdate = UserUpdate
|
|
self.UserDB = UserDB
|