From bcd6ab4401d382cffd09deaa5a6bd0c18ab9692a Mon Sep 17 00:00:00 2001 From: Maxim Kukhtenkov Date: Fri, 19 Jan 2018 19:31:49 -0500 Subject: [PATCH] Update configs and changelog for version 0.9.3 + additional fixes --- demo/requirements.pip | 2 +- docs/changelog.rst | 7 +++++++ docs/installation.rst | 6 +++--- rest_auth/registration/serializers.py | 11 ++++++++--- rest_auth/tests/test_social.py | 9 +-------- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/demo/requirements.pip b/demo/requirements.pip index 7818a9c..7480482 100644 --- a/demo/requirements.pip +++ b/demo/requirements.pip @@ -1,5 +1,5 @@ django>=1.9.0 -django-rest-auth==0.9.2 +django-rest-auth==0.9.3 djangorestframework>=3.7.0 django-allauth>=0.24.1 six==1.9.0 diff --git a/docs/changelog.rst b/docs/changelog.rst index bf88fc8..fa79dbc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,13 @@ Changelog ========= +0.9.3 +----- +- added social connect views +- added check for pre-existing accounts in social login +- prevent double-validation in LoginSerializer +- unit tests and demo project changes for Django 2.0 + 0.9.2 ----- - added permission classes configuration for registration diff --git a/docs/installation.rst b/docs/installation.rst index 8a2d3b6..fa512c5 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -150,14 +150,14 @@ If you are using Twitter for your social authentication, it is a bit different s urlpatterns += [ ..., url(r'^rest-auth/twitter/$', TwitterLogin.as_view(), name='twitter_login') - url(r'^rest-auth/twitter/connect/$', TwitterConnect.as_view(), name='twitter_connect') ] + .. note:: Starting from v0.21.0, django-allauth has dropped support for context processors. Check out http://django-allauth.readthedocs.org/en/latest/changelog.html#from-0-21-0 for more details. Additional Social Connect Views ############################### -If you want to allow connecting existing accounts in addition to just login, you can use connect views: +If you want to allow connecting existing accounts in addition to login, you can use connect views: .. code-block:: python @@ -182,7 +182,7 @@ In urls.py: url(r'^rest-auth/twitter/connect/$', TwitterConnect.as_view(), name='twitter_connect') ] -You can also use additional views to check all social accounts attached to the current authenticated user and disconnect selected social accounts. +You can also use the following views to check all social accounts attached to the current authenticated user and disconnect selected social accounts: .. code-block:: python diff --git a/rest_auth/registration/serializers.py b/rest_auth/registration/serializers.py index 4f99c18..a82dc6c 100644 --- a/rest_auth/registration/serializers.py +++ b/rest_auth/registration/serializers.py @@ -1,4 +1,5 @@ from django.http import HttpRequest +from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.contrib.auth import get_user_model @@ -8,15 +9,19 @@ try: get_username_max_length) from allauth.account.adapter import get_adapter from allauth.account.utils import setup_user_email - from allauth.socialaccount.helpers import complete_social_login - from allauth.socialaccount.models import SocialAccount - from allauth.socialaccount.providers.base import AuthProcess except ImportError: raise ImportError("allauth needs to be added to INSTALLED_APPS.") from rest_framework import serializers from requests.exceptions import HTTPError +# Import is needed only if we are using social login, in which +# case the allauth.socialaccount will be declared +if 'allauth.socialaccount' in settings.INSTALLED_APPS: + from allauth.socialaccount.helpers import complete_social_login + from allauth.socialaccount.models import SocialAccount + from allauth.socialaccount.providers.base import AuthProcess + class SocialAccountSerializer(serializers.ModelSerializer): """ diff --git a/rest_auth/tests/test_social.py b/rest_auth/tests/test_social.py index 6e7a495..830e631 100644 --- a/rest_auth/tests/test_social.py +++ b/rest_auth/tests/test_social.py @@ -322,10 +322,6 @@ class TestSocialConnectAuth(TestsMixin, TestCase): "password2": PASS, "email": EMAIL } - LOGIN_DATA = { - "username": USERNAME, - "password": PASS, - } def setUp(self): self.init() @@ -405,9 +401,6 @@ class TestSocialConnectAuth(TestsMixin, TestCase): self.assertIn('key', self.response.json.keys()) # Test Twitter - self.post(self.logout_url) - self.post(self.login_url, data=self.LOGIN_DATA) - resp_body = { "id": "123123123123", } @@ -439,7 +432,7 @@ class TestSocialConnectAuth(TestsMixin, TestCase): # Try disconnecting accounts self.incorrect_disconnect_url = reverse( - 'social_account_disconnect', args=[999] + 'social_account_disconnect', args=[999999999] ) self.post(self.incorrect_disconnect_url, status_code=404)