Commit 038fd0cf authored by lizonr1's avatar lizonr1

Standarize error response

parent a0125d89
...@@ -17,8 +17,11 @@ class AuthTokenSerializerByEmail(serializers.Serializer): ...@@ -17,8 +17,11 @@ class AuthTokenSerializerByEmail(serializers.Serializer):
def validate(self, attrs): def validate(self, attrs):
email = attrs.get('email') email = attrs.get('email')
password = attrs.get('password') password = attrs.get('password')
queryset = User.objects.all() user_query = User.objects.filter(email__iexact=email)
user_by_email = get_object_or_404(queryset, email__iexact=email) if not user_query:
msg = _('Unable to log in with provided credentials.')
raise serializers.ValidationError(msg)
user_by_email = user_query[0]
if user_by_email and password: if user_by_email and password:
user = authenticate(username=user_by_email.username, password=password) user = authenticate(username=user_by_email.username, password=password)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment