mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-11-22 09:06:40 +03:00
support django-rest-framework v3.0
This commit is contained in:
parent
e9fee3aa92
commit
01ffd4127b
|
@ -7,9 +7,8 @@ class SocialLoginSerializer(serializers.Serializer):
|
|||
|
||||
access_token = serializers.CharField(required=True)
|
||||
|
||||
def validate_access_token(self, attrs, source):
|
||||
access_token = attrs[source]
|
||||
|
||||
def validate(self, attrs):
|
||||
access_token = attrs.get('access_token')
|
||||
view = self.context.get('view')
|
||||
request = self.context.get('request')
|
||||
|
||||
|
@ -38,6 +37,6 @@ class SocialLoginSerializer(serializers.Serializer):
|
|||
if not login.is_existing:
|
||||
login.lookup()
|
||||
login.save(request, connect=True)
|
||||
self.object = {'user': login.account.user}
|
||||
attrs['user'] = login.account.user
|
||||
|
||||
return attrs
|
||||
|
|
|
@ -17,7 +17,6 @@ class LoginSerializer(AuthTokenSerializer):
|
|||
|
||||
def validate(self, attrs):
|
||||
attrs = super(LoginSerializer, self).validate(attrs)
|
||||
|
||||
if 'rest_auth.registration' in settings.INSTALLED_APPS:
|
||||
from allauth.account import app_settings
|
||||
if app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY:
|
||||
|
@ -58,12 +57,12 @@ class PasswordResetSerializer(serializers.Serializer):
|
|||
|
||||
password_reset_form_class = PasswordResetForm
|
||||
|
||||
def validate_email(self, attrs, source):
|
||||
def validate_email(self, value):
|
||||
# Create PasswordResetForm with the serializer
|
||||
self.reset_form = self.password_reset_form_class(data=attrs)
|
||||
self.reset_form = self.password_reset_form_class(data=self.initial_data)
|
||||
if not self.reset_form.is_valid():
|
||||
raise serializers.ValidationError('Error')
|
||||
return attrs
|
||||
return value
|
||||
|
||||
def save(self):
|
||||
request = self.context.get('request')
|
||||
|
@ -115,6 +114,8 @@ class PasswordResetConfirmSerializer(serializers.Serializer):
|
|||
if not default_token_generator.check_token(self.user, attrs['token']):
|
||||
self._errors['token'] = ['Invalid value']
|
||||
|
||||
return attrs
|
||||
|
||||
def save(self):
|
||||
self.set_password_form.save()
|
||||
|
||||
|
@ -138,19 +139,18 @@ class PasswordChangeSerializer(serializers.Serializer):
|
|||
self.request = self.context.get('request')
|
||||
self.user = getattr(self.request, 'user', None)
|
||||
|
||||
def validate_old_password(self, attrs, source):
|
||||
def validate_old_password(self, value):
|
||||
if self.old_password_field_enabled and self.user and \
|
||||
not self.user.check_password(attrs.get(source, '')):
|
||||
not self.user.check_password(value):
|
||||
raise serializers.ValidationError('Invalid password')
|
||||
return attrs
|
||||
return value
|
||||
|
||||
def validate(self, attrs):
|
||||
self.set_password_form = self.set_password_form_class(user=self.user,
|
||||
data=attrs)
|
||||
|
||||
if not self.set_password_form.is_valid():
|
||||
self._errors = self.set_password_form.errors
|
||||
return None
|
||||
raise serializers.ValidationError(self.set_password_form.errors)
|
||||
return attrs
|
||||
|
||||
def save(self):
|
||||
|
|
|
@ -31,7 +31,8 @@ class Login(GenericAPIView):
|
|||
response_serializer = TokenSerializer
|
||||
|
||||
def login(self):
|
||||
self.user = self.serializer.object['user']
|
||||
# import ipdb; ipdb.set_trace()
|
||||
self.user = self.serializer.validated_data['user']
|
||||
self.token, created = self.token_model.objects.get_or_create(
|
||||
user=self.user)
|
||||
if getattr(settings, 'REST_SESSION_LOGIN', True):
|
||||
|
|
4
setup.py
4
setup.py
|
@ -29,8 +29,8 @@ setup(
|
|||
zip_safe=False,
|
||||
install_requires=[
|
||||
'Django>=1.5.0',
|
||||
'djangorestframework>=2.3.13, <3.0',
|
||||
'six>=1.8.0',
|
||||
'djangorestframework>=3.0',
|
||||
'six>=1.9.0',
|
||||
],
|
||||
test_suite='runtests.runtests',
|
||||
include_package_data=True,
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
django-allauth>=0.18.0
|
||||
responses>=0.2.2
|
||||
django-allauth>=0.19.0
|
||||
responses>=0.3.0
|
||||
|
|
Loading…
Reference in New Issue
Block a user