Define on_after_forgot_password with a decorator

This commit is contained in:
François Voron
2019-10-24 09:18:07 +02:00
parent 636dd86987
commit 008a8296f2
6 changed files with 83 additions and 59 deletions

View File

@ -22,9 +22,12 @@ def test_app_client(request, mock_user_db, mock_authentication) -> TestClient:
class User(BaseUser):
pass
fastapi_users = FastAPIUsers(
mock_user_db, mock_authentication, User, request.param, SECRET
)
fastapi_users = FastAPIUsers(mock_user_db, mock_authentication, User, SECRET)
@fastapi_users.on_after_forgot_password()
def on_after_forgot_password():
return request.param()
app = FastAPI()
app.include_router(fastapi_users.router)

View File

@ -8,7 +8,7 @@ from starlette import status
from starlette.testclient import TestClient
from fastapi_users.models import BaseUser, BaseUserDB
from fastapi_users.router import get_user_router
from fastapi_users.router import Events, get_user_router
from fastapi_users.utils import JWT_ALGORITHM, generate_jwt
SECRET = "SECRET"
@ -47,12 +47,11 @@ def test_app_client(
pass
userRouter = get_user_router(
mock_user_db,
User,
mock_authentication,
on_after_forgot_password,
SECRET,
LIFETIME,
mock_user_db, User, mock_authentication, SECRET, LIFETIME
)
userRouter.add_event_handler(
Events.ON_AFTER_FORGOT_PASSWORD, on_after_forgot_password
)
app = FastAPI()