diff --git a/rest_auth/registration/views.py b/rest_auth/registration/views.py index 713c46e..40f895e 100644 --- a/rest_auth/registration/views.py +++ b/rest_auth/registration/views.py @@ -7,6 +7,7 @@ from rest_framework.permissions import AllowAny from rest_framework.generics import CreateAPIView from rest_framework import status +from allauth.account.adapter import get_adapter from allauth.account.views import ConfirmEmailView from allauth.account.utils import complete_signup from allauth.account import app_settings as allauth_settings @@ -101,3 +102,6 @@ class SocialLoginView(LoginView): """ serializer_class = SocialLoginSerializer + + def process_login(self): + get_adapter(self.request).login(self.request, self.user) diff --git a/rest_auth/tests/urls.py b/rest_auth/tests/urls.py index e2e5ee4..63846db 100644 --- a/rest_auth/tests/urls.py +++ b/rest_auth/tests/urls.py @@ -15,7 +15,7 @@ class FacebookLogin(SocialLoginView): adapter_class = FacebookOAuth2Adapter -class TwitterLogin(LoginView): +class TwitterLogin(SocialLoginView): adapter_class = TwitterOAuthAdapter serializer_class = TwitterLoginSerializer diff --git a/rest_auth/views.py b/rest_auth/views.py index c9b1ed8..0761600 100644 --- a/rest_auth/views.py +++ b/rest_auth/views.py @@ -1,4 +1,7 @@ -from django.contrib.auth import login, logout +from django.contrib.auth import ( + login as django_login, + logout as django_logout +) from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ugettext_lazy as _ @@ -11,7 +14,6 @@ from rest_framework.permissions import IsAuthenticated, AllowAny from rest_framework.generics import RetrieveUpdateAPIView from allauth.account import app_settings as allauth_settings -from allauth.account.adapter import get_adapter from .app_settings import ( TokenSerializer, UserDetailsSerializer, LoginSerializer, @@ -38,6 +40,9 @@ class LoginView(GenericAPIView): serializer_class = LoginSerializer token_model = TokenModel + def process_login(self): + django_login(self.request, self.user) + def get_response_serializer(self): if getattr(settings, 'REST_USE_JWT', False): response_serializer = JWTSerializer @@ -54,7 +59,7 @@ class LoginView(GenericAPIView): self.token = create_token(self.token_model, self.user, self.serializer) if getattr(settings, 'REST_SESSION_LOGIN', True): - get_adapter(self.request).login(self.request, self.user) + self.process_login() def get_response(self): serializer_class = self.get_response_serializer() @@ -109,7 +114,7 @@ class LogoutView(APIView): except (AttributeError, ObjectDoesNotExist): pass - logout(request) + django_logout(request) return Response({"success": _("Successfully logged out.")}, status=status.HTTP_200_OK)