diff --git a/fastapi_users/authentication/__init__.py b/fastapi_users/authentication/__init__.py index bed698e0..5c326f27 100644 --- a/fastapi_users/authentication/__init__.py +++ b/fastapi_users/authentication/__init__.py @@ -8,10 +8,10 @@ from fastapi_users.models import UserDB class BaseAuthentication: - userDB: BaseUserDatabase + user_db: BaseUserDatabase - def __init__(self, userDB: BaseUserDatabase): - self.userDB = userDB + def __init__(self, user_db: BaseUserDatabase): + self.user_db = user_db async def get_login_response(self, user: UserDB, response: Response): raise NotImplementedError() diff --git a/fastapi_users/authentication/jwt.py b/fastapi_users/authentication/jwt.py index cb3e0f89..deb6af8c 100644 --- a/fastapi_users/authentication/jwt.py +++ b/fastapi_users/authentication/jwt.py @@ -50,7 +50,7 @@ class JWTAuthentication(BaseAuthentication): except jwt.PyJWTError: raise credentials_exception - user = await self.userDB.get(user_id) + user = await self.user_db.get(user_id) if user is None or not user.is_active: raise credentials_exception diff --git a/fastapi_users/router.py b/fastapi_users/router.py index 068e2967..4d93e582 100644 --- a/fastapi_users/router.py +++ b/fastapi_users/router.py @@ -10,21 +10,21 @@ from fastapi_users.password import get_password_hash class UserRouter: - def __new__(cls, userDB: BaseUserDatabase, auth: BaseAuthentication) -> APIRouter: + def __new__(cls, user_db: BaseUserDatabase, auth: BaseAuthentication) -> APIRouter: router = APIRouter() @router.post("/register", response_model=User) async def register(user: UserCreate): hashed_password = get_password_hash(user.password) db_user = UserDB(**user.dict(), hashed_password=hashed_password) - created_user = await userDB.create(db_user) + created_user = await user_db.create(db_user) return created_user @router.post("/login") async def login( response: Response, credentials: OAuth2PasswordRequestForm = Depends() ): - user = await userDB.authenticate(credentials) + user = await user_db.authenticate(credentials) if user is None: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST) diff --git a/tests/conftest.py b/tests/conftest.py index 4eec8f0a..42025ff5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -61,7 +61,7 @@ class MockAuthentication(BaseAuthentication): return {"token": user.id} async def authenticate(self, token: str) -> UserDB: - user = await self.userDB.get(token) + user = await self.user_db.get(token) if user is None or not user.is_active: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) return user