Automated deployment: Tue Dec 3 20:26:21 UTC 2019 b5b0bbbb01c62563b24c169b761e53d5685d2666

This commit is contained in:
frankie567
2019-12-03 20:26:21 +00:00
parent d871738da1
commit 6d92ab6f60
18 changed files with 1020 additions and 5 deletions

36
src/full_tortoise.py Normal file
View File

@ -0,0 +1,36 @@
from fastapi import FastAPI
from fastapi_users import BaseUser, FastAPIUsers
from fastapi_users.authentication import JWTAuthentication
from fastapi_users.db.tortoise import BaseUserModel, TortoiseUserDatabase
from tortoise import Model
from tortoise.contrib.starlette import register_tortoise
DATABASE_URL = "sqlite://./test.db"
SECRET = "SECRET"
class UserModel(BaseUserModel, Model):
pass
class User(BaseUser):
pass
auth = JWTAuthentication(secret=SECRET, lifetime_seconds=3600)
user_db = TortoiseUserDatabase(UserModel)
app = FastAPI()
register_tortoise(app, db_url=DATABASE_URL, modules={"models": ["test"]})
fastapi_users = FastAPIUsers(user_db, auth, User, SECRET)
app.include_router(fastapi_users.router, prefix="/users", tags=["users"])
@fastapi_users.on_after_register()
def on_after_register(user: User):
print(f"User {user.id} has registered.")
@fastapi_users.on_after_forgot_password()
def on_after_forgot_password(user: User, token: str):
print(f"User {user.id} has forgot their password. Reset token: {token}")