mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-22 00:56:34 +03:00
Pass request to authenticate
This commit is contained in:
parent
95fafe5e0f
commit
a1845aef43
|
@ -21,11 +21,14 @@ class LoginSerializer(serializers.Serializer):
|
||||||
email = serializers.EmailField(required=False, allow_blank=True)
|
email = serializers.EmailField(required=False, allow_blank=True)
|
||||||
password = serializers.CharField(style={'input_type': 'password'})
|
password = serializers.CharField(style={'input_type': 'password'})
|
||||||
|
|
||||||
|
def authenticate(self, **kwargs):
|
||||||
|
return authenticate(self.context['request'], **kwargs)
|
||||||
|
|
||||||
def _validate_email(self, email, password):
|
def _validate_email(self, email, password):
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if email and password:
|
if email and password:
|
||||||
user = authenticate(email=email, password=password)
|
user = self.authenticate(email=email, password=password)
|
||||||
else:
|
else:
|
||||||
msg = _('Must include "email" and "password".')
|
msg = _('Must include "email" and "password".')
|
||||||
raise exceptions.ValidationError(msg)
|
raise exceptions.ValidationError(msg)
|
||||||
|
@ -36,7 +39,7 @@ class LoginSerializer(serializers.Serializer):
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if username and password:
|
if username and password:
|
||||||
user = authenticate(username=username, password=password)
|
user = self.authenticate(username=username, password=password)
|
||||||
else:
|
else:
|
||||||
msg = _('Must include "username" and "password".')
|
msg = _('Must include "username" and "password".')
|
||||||
raise exceptions.ValidationError(msg)
|
raise exceptions.ValidationError(msg)
|
||||||
|
@ -47,9 +50,9 @@ class LoginSerializer(serializers.Serializer):
|
||||||
user = None
|
user = None
|
||||||
|
|
||||||
if email and password:
|
if email and password:
|
||||||
user = authenticate(email=email, password=password)
|
user = self.authenticate(email=email, password=password)
|
||||||
elif username and password:
|
elif username and password:
|
||||||
user = authenticate(username=username, password=password)
|
user = self.authenticate(username=username, password=password)
|
||||||
else:
|
else:
|
||||||
msg = _('Must include either "username" or "email" and "password".')
|
msg = _('Must include either "username" or "email" and "password".')
|
||||||
raise exceptions.ValidationError(msg)
|
raise exceptions.ValidationError(msg)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user