Skip to content

Commit 479a40d

Browse files
authored
Merge pull request #437 from dgilge/request
Pass request to authenticate
2 parents 25263b3 + a1845ae commit 479a40d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

rest_auth/serializers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ class LoginSerializer(serializers.Serializer):
2121
email = serializers.EmailField(required=False, allow_blank=True)
2222
password = serializers.CharField(style={'input_type': 'password'})
2323

24+
def authenticate(self, **kwargs):
25+
return authenticate(self.context['request'], **kwargs)
26+
2427
def _validate_email(self, email, password):
2528
user = None
2629

2730
if email and password:
28-
user = authenticate(email=email, password=password)
31+
user = self.authenticate(email=email, password=password)
2932
else:
3033
msg = _('Must include "email" and "password".')
3134
raise exceptions.ValidationError(msg)
@@ -36,7 +39,7 @@ def _validate_username(self, username, password):
3639
user = None
3740

3841
if username and password:
39-
user = authenticate(username=username, password=password)
42+
user = self.authenticate(username=username, password=password)
4043
else:
4144
msg = _('Must include "username" and "password".')
4245
raise exceptions.ValidationError(msg)
@@ -47,9 +50,9 @@ def _validate_username_email(self, username, email, password):
4750
user = None
4851

4952
if email and password:
50-
user = authenticate(email=email, password=password)
53+
user = self.authenticate(email=email, password=password)
5154
elif username and password:
52-
user = authenticate(username=username, password=password)
55+
user = self.authenticate(username=username, password=password)
5356
else:
5457
msg = _('Must include either "username" or "email" and "password".')
5558
raise exceptions.ValidationError(msg)

0 commit comments

Comments
 (0)