Tivix / django-rest-auth

This app makes it extremely easy to build Django powered SPA's (Single Page App) or Mobile apps exposing all registration and authentication related functionality as CBV's (Class Base View) and REST (JSON)
www.tivix.com
MIT License
2.41k stars 661 forks source link

Can't login without email even though it's supposed to be optional #644

Open Mutusen opened 3 years ago

Mutusen commented 3 years ago

Hi, the documentation says "Optional either username or email can be used, or both. It returns response with token along with it for authentication" but it doesn't work if I don't provide an email address.

In api/serializers.py:

class UserLoginSerializer(serializers.Serializer):
    email = serializers.EmailField(required=False)
    username = serializers.CharField(required=False)
    password = serializers.CharField()
    def validate(self, data):
        email = data['email']
        if not 'email' in data and not 'username' in data :
            raise serializers.ValidationError('Enter Username Or Email')        
        return data

I suggest deleting the line email = data['email'] because the email variable is not used in this function and causes an error if there is no email given.