mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-11-01 18:48:14 +08:00
Define on_after_forgot_password with a decorator
This commit is contained in:
@ -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)
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user