Skip to content

Commit

Permalink
fix(back): adapt email or username backend authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Asiberus committed Mar 1, 2024
1 parent f4a2e6c commit 5d6d3c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions back/authentication/backend_authentication/email_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@


class EmailBackend(ModelBackend):
def authenticate(self, request, email=None, password=None, **kwargs):
def authenticate(self, request, username=None, password=None, **kwargs):
UserModel = get_user_model()

try:
user = UserModel.objects.get(email=email)
user = UserModel.objects.get(email=username)
except UserModel.DoesNotExist:
# Run the default password hasher once to reduce the timing
# difference between an existing and a nonexistent user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

class EmailOrUsernamePasswordAuthentication(BaseAuthentication):
def authenticate(self, request):
username = request.data.get('username')
email = request.data.get('email')
username_or_email = request.data.get('username')
password = request.data.get('password')

if not password or not (username or email):
if not password or not username_or_email:
raise AuthenticationFailed('No credentials provided')

user = authenticate(request, username=username, email=email, password=password)
# Will try on several auth backend to authenticate user
user = authenticate(request, username=username_or_email, password=password)
if not user:
raise AuthenticationFailed('Invalid credentials')

Expand Down

0 comments on commit 5d6d3c8

Please sign in to comment.