2020-03-01 08:56:21 +03:00
|
|
|
from allauth.socialaccount.providers.facebook.views import \
|
|
|
|
FacebookOAuth2Adapter
|
2016-07-18 08:06:28 +03:00
|
|
|
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
|
2020-03-01 08:56:21 +03:00
|
|
|
from dj_rest_auth.registration.views import (SocialAccountDisconnectView,
|
|
|
|
SocialAccountListView,
|
|
|
|
SocialConnectView,
|
|
|
|
SocialLoginView)
|
|
|
|
from dj_rest_auth.social_serializers import (TwitterConnectSerializer,
|
|
|
|
TwitterLoginSerializer)
|
|
|
|
from dj_rest_auth.urls import urlpatterns
|
|
|
|
from django.conf.urls import include, url
|
|
|
|
from django.views.generic import TemplateView
|
2020-06-27 12:58:47 +03:00
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
2020-03-28 19:09:07 +03:00
|
|
|
from rest_framework import permissions
|
2016-07-18 08:06:28 +03:00
|
|
|
from rest_framework.decorators import api_view
|
2020-03-22 13:41:16 +03:00
|
|
|
from rest_framework.response import Response
|
2020-03-28 19:09:07 +03:00
|
|
|
from rest_framework.views import APIView
|
2014-10-08 14:19:15 +04:00
|
|
|
|
2020-03-01 08:56:21 +03:00
|
|
|
from . import django_urls
|
2014-10-08 14:19:15 +04:00
|
|
|
|
|
|
|
|
2020-03-22 13:41:16 +03:00
|
|
|
class ExampleProtectedView(APIView):
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
|
|
|
def get(self, *args, **kwargs):
|
|
|
|
return Response(dict(success=True))
|
|
|
|
|
2020-06-27 12:58:47 +03:00
|
|
|
def post(self, *args, **kwargs):
|
|
|
|
return Response(dict(success=True))
|
|
|
|
|
2020-03-22 13:41:16 +03:00
|
|
|
|
2015-08-07 13:54:45 +03:00
|
|
|
class FacebookLogin(SocialLoginView):
|
2014-10-08 14:19:15 +04:00
|
|
|
adapter_class = FacebookOAuth2Adapter
|
|
|
|
|
2016-07-18 08:06:28 +03:00
|
|
|
|
|
|
|
class TwitterLogin(SocialLoginView):
|
|
|
|
adapter_class = TwitterOAuthAdapter
|
|
|
|
serializer_class = TwitterLoginSerializer
|
|
|
|
|
|
|
|
|
2018-01-20 02:29:38 +03:00
|
|
|
class FacebookConnect(SocialConnectView):
|
|
|
|
adapter_class = FacebookOAuth2Adapter
|
|
|
|
|
|
|
|
|
|
|
|
class TwitterConnect(SocialConnectView):
|
|
|
|
adapter_class = TwitterOAuthAdapter
|
|
|
|
serializer_class = TwitterConnectSerializer
|
|
|
|
|
|
|
|
|
2016-07-18 08:06:28 +03:00
|
|
|
class TwitterLoginSerializerFoo(TwitterLoginSerializer):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['POST'])
|
|
|
|
def twitter_login_view(request):
|
|
|
|
serializer = TwitterLoginSerializerFoo(
|
|
|
|
data={'access_token': '11223344', 'token_secret': '55667788'},
|
|
|
|
context={'request': request}
|
|
|
|
)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
|
|
|
|
|
|
|
|
class TwitterLoginNoAdapter(SocialLoginView):
|
|
|
|
serializer_class = TwitterLoginSerializer
|
|
|
|
|
2020-06-27 12:58:47 +03:00
|
|
|
@ensure_csrf_cookie
|
|
|
|
@api_view(['GET'])
|
|
|
|
def get_csrf_cookie(request):
|
|
|
|
return Response()
|
|
|
|
|
2016-07-18 08:06:28 +03:00
|
|
|
|
2016-01-05 22:46:01 +03:00
|
|
|
urlpatterns += [
|
2020-03-01 06:25:20 +03:00
|
|
|
url(r'^rest-registration/', include('dj_rest_auth.registration.urls')),
|
2015-12-04 11:32:03 +03:00
|
|
|
url(r'^test-admin/', include(django_urls)),
|
2014-10-08 14:19:15 +04:00
|
|
|
url(r'^account-email-verification-sent/$', TemplateView.as_view(),
|
|
|
|
name='account_email_verification_sent'),
|
2016-07-28 21:14:26 +03:00
|
|
|
url(r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(),
|
2014-10-08 14:19:15 +04:00
|
|
|
name='account_confirm_email'),
|
2015-02-27 15:56:29 +03:00
|
|
|
url(r'^social-login/facebook/$', FacebookLogin.as_view(), name='fb_login'),
|
2016-07-18 08:06:28 +03:00
|
|
|
url(r'^social-login/twitter/$', TwitterLogin.as_view(), name='tw_login'),
|
|
|
|
url(r'^social-login/twitter-no-view/$', twitter_login_view, name='tw_login_no_view'),
|
|
|
|
url(r'^social-login/twitter-no-adapter/$', TwitterLoginNoAdapter.as_view(), name='tw_login_no_adapter'),
|
2018-01-20 02:29:38 +03:00
|
|
|
url(r'^social-login/facebook/connect/$', FacebookConnect.as_view(), name='fb_connect'),
|
|
|
|
url(r'^social-login/twitter/connect/$', TwitterConnect.as_view(), name='tw_connect'),
|
|
|
|
url(r'^socialaccounts/$', SocialAccountListView.as_view(), name='social_account_list'),
|
2020-03-22 13:41:16 +03:00
|
|
|
url(r'^protected-view/$', ExampleProtectedView.as_view()),
|
2018-01-20 02:29:38 +03:00
|
|
|
url(r'^socialaccounts/(?P<pk>\d+)/disconnect/$', SocialAccountDisconnectView.as_view(),
|
|
|
|
name='social_account_disconnect'),
|
2020-06-27 12:58:47 +03:00
|
|
|
url(r'^accounts/', include('allauth.socialaccount.urls')),
|
|
|
|
url(r'^getcsrf/', get_csrf_cookie, name='getcsrf'),
|
2016-01-05 22:46:01 +03:00
|
|
|
]
|