mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-14 18:58:10 +08:00
Revamp implementation with a manager layer and db class as dependency callable
This commit is contained in:
@ -3,13 +3,13 @@ from fastapi.security import OAuth2PasswordRequestForm
|
||||
|
||||
from fastapi_users import models
|
||||
from fastapi_users.authentication import Authenticator, BaseAuthentication
|
||||
from fastapi_users.db import BaseUserDatabase
|
||||
from fastapi_users.manager import UserManager, UserManagerDependency
|
||||
from fastapi_users.router.common import ErrorCode
|
||||
|
||||
|
||||
def get_auth_router(
|
||||
backend: BaseAuthentication,
|
||||
user_db: BaseUserDatabase[models.BaseUserDB],
|
||||
get_user_manager: UserManagerDependency[models.BaseUserDB],
|
||||
authenticator: Authenticator,
|
||||
requires_verification: bool = False,
|
||||
) -> APIRouter:
|
||||
@ -21,9 +21,11 @@ def get_auth_router(
|
||||
|
||||
@router.post("/login")
|
||||
async def login(
|
||||
response: Response, credentials: OAuth2PasswordRequestForm = Depends()
|
||||
response: Response,
|
||||
credentials: OAuth2PasswordRequestForm = Depends(),
|
||||
user_manager: UserManager[models.BaseUserDB] = Depends(get_user_manager),
|
||||
):
|
||||
user = await user_db.authenticate(credentials)
|
||||
user = await user_manager.authenticate(credentials)
|
||||
|
||||
if user is None or not user.is_active:
|
||||
raise HTTPException(
|
||||
|
Reference in New Issue
Block a user