mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-07-22 05:29:46 +03:00
Update serializers.py
Authentication with email!
This commit is contained in:
parent
b124aaf273
commit
341a327840
|
@ -25,7 +25,12 @@ class LoginSerializer(serializers.Serializer):
|
|||
user = None
|
||||
|
||||
if email and password:
|
||||
user = authenticate(email=email, password=password)
|
||||
try:
|
||||
username = UserModel.objects.get(email__iexact=email).get_username()
|
||||
user = authenticate(username=username, password=password)
|
||||
except UserModel.DoesNotExist:
|
||||
msg = _('Unable to log in with provided credentials.')
|
||||
raise exceptions.ValidationError(msg)
|
||||
else:
|
||||
msg = _('Must include "email" and "password".')
|
||||
raise exceptions.ValidationError(msg)
|
||||
|
@ -47,7 +52,12 @@ class LoginSerializer(serializers.Serializer):
|
|||
user = None
|
||||
|
||||
if email and password:
|
||||
user = authenticate(email=email, password=password)
|
||||
try:
|
||||
username = UserModel.objects.get(email__iexact=email).get_username()
|
||||
user = authenticate(username=username, password=password)
|
||||
except UserModel.DoesNotExist:
|
||||
msg = _('Unable to log in with provided credentials.')
|
||||
raise exceptions.ValidationError(msg)
|
||||
elif username and password:
|
||||
user = authenticate(username=username, password=password)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user