From a1845aef434c788561b88616bb151abaa7e9c67b Mon Sep 17 00:00:00 2001 From: Daniel <33256939+dgilge@users.noreply.github.com> Date: Thu, 14 Jun 2018 00:06:20 +0200 Subject: [PATCH] Pass request to authenticate --- rest_auth/serializers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index 45729b2..2ea6550 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -21,11 +21,14 @@ class LoginSerializer(serializers.Serializer): email = serializers.EmailField(required=False, allow_blank=True) password = serializers.CharField(style={'input_type': 'password'}) + def authenticate(self, **kwargs): + return authenticate(self.context['request'], **kwargs) + def _validate_email(self, email, password): user = None if email and password: - user = authenticate(email=email, password=password) + user = self.authenticate(email=email, password=password) else: msg = _('Must include "email" and "password".') raise exceptions.ValidationError(msg) @@ -36,7 +39,7 @@ class LoginSerializer(serializers.Serializer): user = None if username and password: - user = authenticate(username=username, password=password) + user = self.authenticate(username=username, password=password) else: msg = _('Must include "username" and "password".') raise exceptions.ValidationError(msg) @@ -47,9 +50,9 @@ class LoginSerializer(serializers.Serializer): user = None if email and password: - user = authenticate(email=email, password=password) + user = self.authenticate(email=email, password=password) elif username and password: - user = authenticate(username=username, password=password) + user = self.authenticate(username=username, password=password) else: msg = _('Must include either "username" or "email" and "password".') raise exceptions.ValidationError(msg)