mirror of
https://github.com/fastapi-users/fastapi-users.git
synced 2025-08-15 11:11:16 +08:00
* Replace unused `for` index with underscore * Use `items()` to directly unpack dictionary values * Merge duplicate blocks in conditional * Use `any()` instead of for loop * Format __init__.py
This commit is contained in:
@ -152,11 +152,10 @@ class Authenticator:
|
|||||||
if active and not user.is_active:
|
if active and not user.is_active:
|
||||||
status_code = status.HTTP_401_UNAUTHORIZED
|
status_code = status.HTTP_401_UNAUTHORIZED
|
||||||
user = None
|
user = None
|
||||||
elif verified and not user.is_verified:
|
elif (
|
||||||
|
verified and not user.is_verified or superuser and not user.is_superuser
|
||||||
|
):
|
||||||
user = None
|
user = None
|
||||||
elif superuser and not user.is_superuser:
|
|
||||||
user = None
|
|
||||||
|
|
||||||
if not user and not optional:
|
if not user and not optional:
|
||||||
raise HTTPException(status_code=status_code)
|
raise HTTPException(status_code=status_code)
|
||||||
return user
|
return user
|
||||||
|
@ -307,7 +307,10 @@ class BaseUserManager(Generic[models.UC, models.UD]):
|
|||||||
if not user.is_active:
|
if not user.is_active:
|
||||||
raise UserInactive()
|
raise UserInactive()
|
||||||
|
|
||||||
token_data = {"user_id": str(user.id), "aud": self.reset_password_token_audience}
|
token_data = {
|
||||||
|
"user_id": str(user.id),
|
||||||
|
"aud": self.reset_password_token_audience,
|
||||||
|
}
|
||||||
token = generate_jwt(
|
token = generate_jwt(
|
||||||
token_data,
|
token_data,
|
||||||
self.reset_password_token_secret,
|
self.reset_password_token_secret,
|
||||||
@ -535,8 +538,7 @@ class BaseUserManager(Generic[models.UC, models.UD]):
|
|||||||
return user
|
return user
|
||||||
|
|
||||||
async def _update(self, user: models.UD, update_dict: Dict[str, Any]) -> models.UD:
|
async def _update(self, user: models.UD, update_dict: Dict[str, Any]) -> models.UD:
|
||||||
for field in update_dict:
|
for field, value in update_dict.items():
|
||||||
value = update_dict[field]
|
|
||||||
if field == "email" and value != user.email:
|
if field == "email" and value != user.email:
|
||||||
try:
|
try:
|
||||||
await self.get_by_email(value)
|
await self.get_by_email(value)
|
||||||
|
@ -50,11 +50,10 @@ def get_oauth_router(
|
|||||||
scopes: List[str] = Query(None),
|
scopes: List[str] = Query(None),
|
||||||
):
|
):
|
||||||
# Check that authentication_backend exists
|
# Check that authentication_backend exists
|
||||||
backend_exists = False
|
backend_exists = any(
|
||||||
for backend in authenticator.backends:
|
backend.name == authentication_backend for backend in authenticator.backends
|
||||||
if backend.name == authentication_backend:
|
)
|
||||||
backend_exists = True
|
|
||||||
break
|
|
||||||
if not backend_exists:
|
if not backend_exists:
|
||||||
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
|
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
@ -137,5 +137,5 @@ async def test_authenticator_none_enabled(get_test_auth_client, user):
|
|||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_authenticators_with_same_name(get_test_auth_client):
|
async def test_authenticators_with_same_name(get_test_auth_client):
|
||||||
with pytest.raises(DuplicateBackendNamesError):
|
with pytest.raises(DuplicateBackendNamesError):
|
||||||
async for client in get_test_auth_client([BackendNone(), BackendNone()]):
|
async for _ in get_test_auth_client([BackendNone(), BackendNone()]):
|
||||||
pass
|
pass
|
||||||
|
Reference in New Issue
Block a user