mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-11-07 00:19:10 +08:00
* Implement password validation mechanism * Add invalid password reason * Always pass user in password validator * Add password validation documentation
1.8 KiB
1.8 KiB
User model
FastAPI Users defines a minimal User model for authentication purposes. It is structured like this:
id(UUID4) – Unique identifier of the user. Defaults to a UUID4.email(str) – Email of the user. Validated byemail-validator.is_active(bool) – Whether or not the user is active. If not, login and forgot password requests will be denied. Defaults toTrue.is_verified(bool) – Whether or not the user is verified. Optional but helpful with theverifyrouter logic. Defaults toFalse.is_superuser(bool) – Whether or not the user is a superuser. Useful to implement administration logic. Defaults toFalse.
Define your models
There are four Pydantic models variations provided as mixins:
BaseUser, which provides the basic fields and validation ;BaseCreateUser, dedicated to user registration, which consists of compulsoryemailandpasswordfields ;BaseUpdateUser, dedicated to user profile update, which adds an optionalpasswordfield ;BaseUserDB, which is a representation of the user in database, adding ahashed_passwordfield.
You should define each of those variations, inheriting from each mixin:
from fastapi_users import models
class User(models.BaseUser):
pass
class UserCreate(models.BaseUserCreate):
pass
class UserUpdate(User, models.BaseUserUpdate):
pass
class UserDB(User, models.BaseUserDB):
pass
You can of course add your own properties there to fit to your needs!
Next steps
Depending on your database backend, the database configuration will differ a bit.