mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2025-02-16 18:00:35 +03:00
appending all views with View
This commit is contained in:
parent
4a3ea85f44
commit
ad94008503
|
@ -6,17 +6,17 @@ Configuration
|
||||||
You can define your custom serializers for each endpoint without overriding urls and views by adding ``REST_AUTH_SERIALIZERS`` dictionary in your django settings.
|
You can define your custom serializers for each endpoint without overriding urls and views by adding ``REST_AUTH_SERIALIZERS`` dictionary in your django settings.
|
||||||
Possible key values:
|
Possible key values:
|
||||||
|
|
||||||
- LOGIN_SERIALIZER - serializer class in ``rest_auth.views.Login``, default value ``rest_auth.serializers.LoginSerializer``
|
- LOGIN_SERIALIZER - serializer class in ``rest_auth.views.LoginView``, default value ``rest_auth.serializers.LoginSerializer``
|
||||||
|
|
||||||
- TOKEN_SERIALIZER - response for successful authentication in ``rest_auth.views.Login``, default value ``rest_auth.serializers.TokenSerializer``
|
- TOKEN_SERIALIZER - response for successful authentication in ``rest_auth.views.LoginView``, default value ``rest_auth.serializers.TokenSerializer``
|
||||||
|
|
||||||
- USER_DETAILS_SERIALIZER - serializer class in ``rest_auth.views.UserDetails``, default value ``rest_auth.serializers.UserDetailsSerializer``
|
- USER_DETAILS_SERIALIZER - serializer class in ``rest_auth.views.UserDetailsView``, default value ``rest_auth.serializers.UserDetailsSerializer``
|
||||||
|
|
||||||
- PASSWORD_RESET_SERIALIZER - serializer class in ``rest_auth.views.PasswordReset``, default value ``rest_auth.serializers.PasswordResetSerializer``
|
- PASSWORD_RESET_SERIALIZER - serializer class in ``rest_auth.views.PasswordResetView``, default value ``rest_auth.serializers.PasswordResetSerializer``
|
||||||
|
|
||||||
- PASSWORD_RESET_CONFIRM_SERIALIZER - serializer class in ``rest_auth.views.PasswordResetConfirm``, default value ``rest_auth.serializers.PasswordResetConfirmSerializer``
|
- PASSWORD_RESET_CONFIRM_SERIALIZER - serializer class in ``rest_auth.views.PasswordResetConfirmView``, default value ``rest_auth.serializers.PasswordResetConfirmSerializer``
|
||||||
|
|
||||||
- PASSWORD_CHANGE_SERIALIZER - serializer class in ``rest_auth.views.PasswordChange``, default value ``rest_auth.serializers.PasswordChangeSerializer``
|
- PASSWORD_CHANGE_SERIALIZER - serializer class in ``rest_auth.views.PasswordChangeView``, default value ``rest_auth.serializers.PasswordChangeSerializer``
|
||||||
|
|
||||||
|
|
||||||
Example configuration:
|
Example configuration:
|
||||||
|
|
|
@ -31,7 +31,7 @@ FAQ
|
||||||
# custom fields for user
|
# custom fields for user
|
||||||
company_name = models.CharField(max_length=100)
|
company_name = models.CharField(max_length=100)
|
||||||
|
|
||||||
To allow update user details within one request send to rest_auth.views.UserDetails view, create serializer like this:
|
To allow update user details within one request send to rest_auth.views.UserDetailsView view, create serializer like this:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
|
|
@ -91,14 +91,14 @@ Using ``django-allauth``, ``django-rest-auth`` provides helpful class for creati
|
||||||
|
|
||||||
3. Add Social Application in django admin panel
|
3. Add Social Application in django admin panel
|
||||||
|
|
||||||
4. Create new view as a subclass of ``rest_auth.registration.views.SocialLogin`` with ``FacebookOAuth2Adapter`` adapter as an attribute:
|
4. Create new view as a subclass of ``rest_auth.registration.views.SocialLoginView`` with ``FacebookOAuth2Adapter`` adapter as an attribute:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
||||||
from rest_auth.registration.views import SocialLogin
|
from rest_auth.registration.views import SocialLoginView
|
||||||
|
|
||||||
class FacebookLogin(SocialLogin):
|
class FacebookLogin(SocialLoginView):
|
||||||
adapter_class = FacebookOAuth2Adapter
|
adapter_class = FacebookOAuth2Adapter
|
||||||
|
|
||||||
5. Create url for FacebookLogin view:
|
5. Create url for FacebookLogin view:
|
||||||
|
|
|
@ -26,7 +26,7 @@ class SocialLoginSerializer(serializers.Serializer):
|
||||||
:param app: `allauth.socialaccount.SocialApp` instance
|
:param app: `allauth.socialaccount.SocialApp` instance
|
||||||
:param token: `allauth.socialaccount.SocialToken` instance
|
:param token: `allauth.socialaccount.SocialToken` instance
|
||||||
:param response: Provider's response for OAuth1. Not used in the
|
:param response: Provider's response for OAuth1. Not used in the
|
||||||
:return: :return: A populated instance of the `allauth.socialaccount.SocialLogin` instance
|
:return: :return: A populated instance of the `allauth.socialaccount.SocialLoginView` instance
|
||||||
"""
|
"""
|
||||||
request = self._get_request()
|
request = self._get_request()
|
||||||
social_login = adapter.complete_login(request, app, token, response=response)
|
social_login = adapter.complete_login(request, app, token, response=response)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from .views import Register, VerifyEmail
|
from .views import RegisterView, VerifyEmailView
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
url(r'^$', Register.as_view(), name='rest_register'),
|
url(r'^$', RegisterView.as_view(), name='rest_register'),
|
||||||
url(r'^verify-email/$', VerifyEmail.as_view(), name='rest_verify_email'),
|
url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
|
||||||
|
|
||||||
# This url is used by django-allauth and empty TemplateView is
|
# This url is used by django-allauth and empty TemplateView is
|
||||||
# defined just to allow reverse() call inside app, for example when email
|
# defined just to allow reverse() call inside app, for example when email
|
||||||
|
|
|
@ -11,10 +11,10 @@ from allauth.account import app_settings
|
||||||
|
|
||||||
from rest_auth.app_settings import UserDetailsSerializer, TokenSerializer
|
from rest_auth.app_settings import UserDetailsSerializer, TokenSerializer
|
||||||
from rest_auth.registration.serializers import SocialLoginSerializer
|
from rest_auth.registration.serializers import SocialLoginSerializer
|
||||||
from rest_auth.views import Login
|
from rest_auth.views import LoginView
|
||||||
|
|
||||||
|
|
||||||
class Register(APIView, SignupView):
|
class RegisterView(APIView, SignupView):
|
||||||
"""
|
"""
|
||||||
Accepts the credentials and creates a new user
|
Accepts the credentials and creates a new user
|
||||||
if user does not exist already
|
if user does not exist already
|
||||||
|
@ -69,7 +69,7 @@ class Register(APIView, SignupView):
|
||||||
return Response(self.form.errors, status=status.HTTP_400_BAD_REQUEST)
|
return Response(self.form.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
class VerifyEmail(APIView, ConfirmEmailView):
|
class VerifyEmailView(APIView, ConfirmEmailView):
|
||||||
|
|
||||||
permission_classes = (AllowAny,)
|
permission_classes = (AllowAny,)
|
||||||
allowed_methods = ('POST', 'OPTIONS', 'HEAD')
|
allowed_methods = ('POST', 'OPTIONS', 'HEAD')
|
||||||
|
@ -84,14 +84,14 @@ class VerifyEmail(APIView, ConfirmEmailView):
|
||||||
return Response({'message': 'ok'}, status=status.HTTP_200_OK)
|
return Response({'message': 'ok'}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class SocialLogin(Login):
|
class SocialLoginView(LoginView):
|
||||||
"""
|
"""
|
||||||
class used for social authentications
|
class used for social authentications
|
||||||
example usage for facebook with access_token
|
example usage for facebook with access_token
|
||||||
-------------
|
-------------
|
||||||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
||||||
|
|
||||||
class FacebookLogin(SocialLogin):
|
class FacebookLogin(SocialLoginView):
|
||||||
adapter_class = FacebookOAuth2Adapter
|
adapter_class = FacebookOAuth2Adapter
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class SocialLogin(Login):
|
||||||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
||||||
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
|
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
|
||||||
|
|
||||||
class FacebookLogin(SocialLogin):
|
class FacebookLogin(SocialLoginView):
|
||||||
adapter_class = FacebookOAuth2Adapter
|
adapter_class = FacebookOAuth2Adapter
|
||||||
client_class = OAuth2Client
|
client_class = OAuth2Client
|
||||||
callback_url = 'localhost:8000'
|
callback_url = 'localhost:8000'
|
||||||
|
|
|
@ -5,10 +5,10 @@ import rest_auth.django_test_urls
|
||||||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
|
||||||
|
|
||||||
from rest_auth.urls import urlpatterns
|
from rest_auth.urls import urlpatterns
|
||||||
from rest_auth.registration.views import SocialLogin
|
from rest_auth.registration.views import SocialLoginView
|
||||||
|
|
||||||
|
|
||||||
class FacebookLogin(SocialLogin):
|
class FacebookLogin(SocialLoginView):
|
||||||
adapter_class = FacebookOAuth2Adapter
|
adapter_class = FacebookOAuth2Adapter
|
||||||
|
|
||||||
urlpatterns += patterns(
|
urlpatterns += patterns(
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
from django.conf.urls import patterns, url
|
from django.conf.urls import patterns, url
|
||||||
|
|
||||||
from rest_auth.views import (
|
from rest_auth.views import (
|
||||||
Login, Logout, UserDetails, PasswordChange,
|
LoginView, LogoutView, UserDetailsView, PasswordChangeView,
|
||||||
PasswordReset, PasswordResetConfirm
|
PasswordResetView, PasswordResetConfirmView
|
||||||
)
|
)
|
||||||
|
|
||||||
urlpatterns = patterns(
|
urlpatterns = patterns(
|
||||||
'',
|
'',
|
||||||
# URLs that do not require a session or valid token
|
# URLs that do not require a session or valid token
|
||||||
url(r'^password/reset/$', PasswordReset.as_view(),
|
url(r'^password/reset/$', PasswordResetView.as_view(),
|
||||||
name='rest_password_reset'),
|
name='rest_password_reset'),
|
||||||
url(r'^password/reset/confirm/$', PasswordResetConfirm.as_view(),
|
url(r'^password/reset/confirm/$', PasswordResetConfirmView.as_view(),
|
||||||
name='rest_password_reset_confirm'),
|
name='rest_password_reset_confirm'),
|
||||||
url(r'^login/$', Login.as_view(), name='rest_login'),
|
url(r'^login/$', LoginView.as_view(), name='rest_login'),
|
||||||
# URLs that require a user to be logged in with a valid session / token.
|
# URLs that require a user to be logged in with a valid session / token.
|
||||||
url(r'^logout/$', Logout.as_view(), name='rest_logout'),
|
url(r'^logout/$', LogoutView.as_view(), name='rest_logout'),
|
||||||
url(r'^user/$', UserDetails.as_view(), name='rest_user_details'),
|
url(r'^user/$', UserDetailsView.as_view(), name='rest_user_details'),
|
||||||
url(r'^password/change/$', PasswordChange.as_view(),
|
url(r'^password/change/$', PasswordChangeView.as_view(),
|
||||||
name='rest_password_change'),
|
name='rest_password_change'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,7 @@ from .app_settings import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Login(GenericAPIView):
|
class LoginView(GenericAPIView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Check the credentials and return the REST Token
|
Check the credentials and return the REST Token
|
||||||
|
@ -57,7 +57,7 @@ class Login(GenericAPIView):
|
||||||
return self.get_response()
|
return self.get_response()
|
||||||
|
|
||||||
|
|
||||||
class Logout(APIView):
|
class LogoutView(APIView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Calls Django logout method and delete the Token object
|
Calls Django logout method and delete the Token object
|
||||||
|
@ -79,7 +79,7 @@ class Logout(APIView):
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class UserDetails(RetrieveUpdateAPIView):
|
class UserDetailsView(RetrieveUpdateAPIView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Returns User's details in JSON format.
|
Returns User's details in JSON format.
|
||||||
|
@ -97,7 +97,7 @@ class UserDetails(RetrieveUpdateAPIView):
|
||||||
return self.request.user
|
return self.request.user
|
||||||
|
|
||||||
|
|
||||||
class PasswordReset(GenericAPIView):
|
class PasswordResetView(GenericAPIView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Calls Django Auth PasswordResetForm save method.
|
Calls Django Auth PasswordResetForm save method.
|
||||||
|
@ -124,7 +124,7 @@ class PasswordReset(GenericAPIView):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PasswordResetConfirm(GenericAPIView):
|
class PasswordResetConfirmView(GenericAPIView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Password reset e-mail link is confirmed, therefore this resets the user's password.
|
Password reset e-mail link is confirmed, therefore this resets the user's password.
|
||||||
|
@ -147,7 +147,7 @@ class PasswordResetConfirm(GenericAPIView):
|
||||||
return Response({"success": "Password has been reset with the new password."})
|
return Response({"success": "Password has been reset with the new password."})
|
||||||
|
|
||||||
|
|
||||||
class PasswordChange(GenericAPIView):
|
class PasswordChangeView(GenericAPIView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Calls Django Auth SetPasswordForm save method.
|
Calls Django Auth SetPasswordForm save method.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user