mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-07-22 05:29:46 +03:00
Authentication with email
This commit is contained in:
parent
e6d1077ae2
commit
602c764a23
|
@ -25,7 +25,12 @@ class LoginSerializer(serializers.Serializer):
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if email and password:
|
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:
|
else:
|
||||||
msg = _('Must include "email" and "password".')
|
msg = _('Must include "email" and "password".')
|
||||||
raise exceptions.ValidationError(msg)
|
raise exceptions.ValidationError(msg)
|
||||||
|
@ -47,7 +52,12 @@ class LoginSerializer(serializers.Serializer):
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if email and password:
|
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:
|
elif username and password:
|
||||||
user = authenticate(username=username, password=password)
|
user = authenticate(username=username, password=password)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user