class UserCreate(models.BaseUserCreate):
    pass


class UserUpdate(User, models.BaseUserUpdate):
    pass


class UserDB(User, models.BaseUserDB, PydanticModel):
    class Config:
        orm_mode = True
        orig_model = UserModel


user_db = TortoiseUserDatabase(UserDB, UserModel, OAuthAccountModel)
app = FastAPI()
register_tortoise(
    app,
    db_url=DATABASE_URL,
    modules={"models": ["oauth_full_tortoise"]},
    generate_schemas=True,
)


def on_after_register(user: UserDB, request: Request):
    print(f"User {user.id} has registered.")


def on_after_forgot_password(user: UserDB, token: str, request: Request):
    print(f"User {user.id} has forgot their password. Reset token: {token}")
示例#2
0
from tortoise.contrib.starlette import register_tortoise


class User(models.BaseUser):
    pass


class UserCreate(User, models.BaseUserCreate):
    pass


class UserUpdate(User, models.BaseUserUpdate):
    pass


class UserDB(User, models.BaseUserDB):
    pass


DATABASE_URL = "sqlite://./test.db"


class UserModel(TortoiseBaseUserModel):
    pass


user_db = TortoiseUserDatabase(UserDB, UserModel)
app = FastAPI()

register_tortoise(app, modules={"models": ["path_to_your_package"]})
示例#3
0
文件: db.py 项目: domidemps/popote
async def get_user_db():
    yield TortoiseUserDatabase(UserDB, UserModel)
async def get_user_db():
    yield TortoiseUserDatabase(UserDB, UserModel, OAuthAccount)
示例#5
0
from fastapi_users import FastAPIUsers
from fastapi_users.authentication import JWTAuthentication
from fastapi_users.db import TortoiseUserDatabase

from server.models import User
from server.serializers.users import UserCreateSerializer, UserDBSerializer, UserSerializer, UserUpdateSerializer
from server.settings import settings

jwt_authentication = JWTAuthentication(secret=settings.secret_key,
                                       lifetime_seconds=settings.jwt_lifetime,
                                       tokenUrl='/api/auth/jwt/login')
user_db = TortoiseUserDatabase(UserDBSerializer, User)
fastapi_users = FastAPIUsers(
    user_db,
    [jwt_authentication],
    UserSerializer,
    UserCreateSerializer,
    UserUpdateSerializer,
    UserDBSerializer,
)