Update serializers.py

Authentication with email!
This commit is contained in:
kdzch 2017-09-24 15:50:34 -05:00 committed by GitHub
parent b124aaf273
commit 341a327840

View File

@ -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: