diff --git a/api/main.py b/api/main.py index 239179b68..a44ccc889 100644 --- a/api/main.py +++ b/api/main.py @@ -26,7 +26,6 @@ from bson import ObjectId, errors from pymongo.errors import DuplicateKeyError from fastapi_users import FastAPIUsers -from fastapi_users.db import BeanieUserDatabase from beanie import PydanticObjectId from .auth import Authentication from .db import Database @@ -167,7 +166,7 @@ async def register(request: Request, user: UserCreate, groups.append(group) user.groups = groups created_user = await register_router.routes[0].endpoint( - request, user, UserManager(BeanieUserDatabase(User))) + request, user, get_user_manager()) # Update user to be an admin user explicitly if requested as # `fastapi-users` register route does not allow it if user.is_superuser: @@ -244,7 +243,7 @@ async def update_me(request: Request, user: UserUpdate, if groups: user.groups = groups return await users_router.routes[1].endpoint( - request, user, current_user, UserManager(BeanieUserDatabase(User))) + request, user, current_user, get_user_manager()) @app.patch("/user/{user_id}", response_model=UserRead, tags=["user"], @@ -281,7 +280,7 @@ async def update_user(user_id: str, request: Request, user: UserUpdate, user.groups = groups updated_user = await users_router.routes[3].endpoint( - user, request, user_from_id, UserManager(BeanieUserDatabase(User))) + user, request, user_from_id, get_user_manager()) # Update user to be an admin user explicitly if requested as # `fastapi-users` user update route does not allow it if user.is_superuser: @@ -334,8 +333,7 @@ async def update_password(request: Request, credentials: OAuth2PasswordRequestForm = Depends(), new_password: str = Form(None)): """Update user password""" - user = await UserManager(BeanieUserDatabase(User)).authenticate( - credentials) + user = await get_user_manager().authenticate(credentials) if user is None or not user.is_active: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, @@ -344,8 +342,8 @@ async def update_password(request: Request, user_update = UserUpdate(password=new_password) user_from_username = await db.find_one(User, username=credentials.username) await users_router.routes[3].endpoint( - user_update, request, user_from_username, - UserManager(BeanieUserDatabase(User))) + user_update, request, user_from_username, get_user_manager() + ) # -----------------------------------------------------------------------------