mirror of
				https://github.com/Tivix/django-rest-auth.git
				synced 2025-11-04 09:37: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.
 | 
			
		||||
    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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ FAQ
 | 
			
		|||
            # custom fields for user
 | 
			
		||||
            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
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -91,14 +91,14 @@ Using ``django-allauth``, ``django-rest-auth`` provides helpful class for creati
 | 
			
		|||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
5. Create url for FacebookLogin view:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,7 @@ class SocialLoginSerializer(serializers.Serializer):
 | 
			
		|||
        :param app: `allauth.socialaccount.SocialApp` instance
 | 
			
		||||
        :param token: `allauth.socialaccount.SocialToken` instance
 | 
			
		||||
        :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()
 | 
			
		||||
        social_login = adapter.complete_login(request, app, token, response=response)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,12 +1,12 @@
 | 
			
		|||
from django.views.generic import TemplateView
 | 
			
		||||
from django.conf.urls import patterns, url
 | 
			
		||||
 | 
			
		||||
from .views import Register, VerifyEmail
 | 
			
		||||
from .views import RegisterView, VerifyEmailView
 | 
			
		||||
 | 
			
		||||
urlpatterns = patterns(
 | 
			
		||||
    '',
 | 
			
		||||
    url(r'^$', Register.as_view(), name='rest_register'),
 | 
			
		||||
    url(r'^verify-email/$', VerifyEmail.as_view(), name='rest_verify_email'),
 | 
			
		||||
    url(r'^$', RegisterView.as_view(), name='rest_register'),
 | 
			
		||||
    url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'),
 | 
			
		||||
 | 
			
		||||
    # This url is used by django-allauth and empty TemplateView is
 | 
			
		||||
    # 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.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
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VerifyEmail(APIView, ConfirmEmailView):
 | 
			
		||||
class VerifyEmailView(APIView, ConfirmEmailView):
 | 
			
		||||
 | 
			
		||||
    permission_classes = (AllowAny,)
 | 
			
		||||
    allowed_methods = ('POST', 'OPTIONS', 'HEAD')
 | 
			
		||||
| 
						 | 
				
			
			@ -84,14 +84,14 @@ class VerifyEmail(APIView, ConfirmEmailView):
 | 
			
		|||
        return Response({'message': 'ok'}, status=status.HTTP_200_OK)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class SocialLogin(Login):
 | 
			
		||||
class SocialLoginView(LoginView):
 | 
			
		||||
    """
 | 
			
		||||
    class used for social authentications
 | 
			
		||||
    example usage for facebook with access_token
 | 
			
		||||
    -------------
 | 
			
		||||
    from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
 | 
			
		||||
 | 
			
		||||
    class FacebookLogin(SocialLogin):
 | 
			
		||||
    class FacebookLogin(SocialLoginView):
 | 
			
		||||
        adapter_class = FacebookOAuth2Adapter
 | 
			
		||||
    -------------
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +101,7 @@ class SocialLogin(Login):
 | 
			
		|||
    from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
 | 
			
		||||
    from allauth.socialaccount.providers.oauth2.client import OAuth2Client
 | 
			
		||||
 | 
			
		||||
    class FacebookLogin(SocialLogin):
 | 
			
		||||
    class FacebookLogin(SocialLoginView):
 | 
			
		||||
        adapter_class = FacebookOAuth2Adapter
 | 
			
		||||
         client_class = OAuth2Client
 | 
			
		||||
         callback_url = 'localhost:8000'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,10 +5,10 @@ import rest_auth.django_test_urls
 | 
			
		|||
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
urlpatterns += patterns(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,21 +1,21 @@
 | 
			
		|||
from django.conf.urls import patterns, url
 | 
			
		||||
 | 
			
		||||
from rest_auth.views import (
 | 
			
		||||
    Login, Logout, UserDetails, PasswordChange,
 | 
			
		||||
    PasswordReset, PasswordResetConfirm
 | 
			
		||||
    LoginView, LogoutView, UserDetailsView, PasswordChangeView,
 | 
			
		||||
    PasswordResetView, PasswordResetConfirmView
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
urlpatterns = patterns(
 | 
			
		||||
    '',
 | 
			
		||||
    # 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'),
 | 
			
		||||
    url(r'^password/reset/confirm/$', PasswordResetConfirm.as_view(),
 | 
			
		||||
    url(r'^password/reset/confirm/$', PasswordResetConfirmView.as_view(),
 | 
			
		||||
        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.
 | 
			
		||||
    url(r'^logout/$', Logout.as_view(), name='rest_logout'),
 | 
			
		||||
    url(r'^user/$', UserDetails.as_view(), name='rest_user_details'),
 | 
			
		||||
    url(r'^password/change/$', PasswordChange.as_view(),
 | 
			
		||||
    url(r'^logout/$', LogoutView.as_view(), name='rest_logout'),
 | 
			
		||||
    url(r'^user/$', UserDetailsView.as_view(), name='rest_user_details'),
 | 
			
		||||
    url(r'^password/change/$', PasswordChangeView.as_view(),
 | 
			
		||||
        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
 | 
			
		||||
| 
						 | 
				
			
			@ -57,7 +57,7 @@ class Login(GenericAPIView):
 | 
			
		|||
        return self.get_response()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Logout(APIView):
 | 
			
		||||
class LogoutView(APIView):
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    Calls Django logout method and delete the Token object
 | 
			
		||||
| 
						 | 
				
			
			@ -79,7 +79,7 @@ class Logout(APIView):
 | 
			
		|||
                        status=status.HTTP_200_OK)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class UserDetails(RetrieveUpdateAPIView):
 | 
			
		||||
class UserDetailsView(RetrieveUpdateAPIView):
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    Returns User's details in JSON format.
 | 
			
		||||
| 
						 | 
				
			
			@ -97,7 +97,7 @@ class UserDetails(RetrieveUpdateAPIView):
 | 
			
		|||
        return self.request.user
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PasswordReset(GenericAPIView):
 | 
			
		||||
class PasswordResetView(GenericAPIView):
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    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.
 | 
			
		||||
| 
						 | 
				
			
			@ -147,7 +147,7 @@ class PasswordResetConfirm(GenericAPIView):
 | 
			
		|||
        return Response({"success": "Password has been reset with the new password."})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PasswordChange(GenericAPIView):
 | 
			
		||||
class PasswordChangeView(GenericAPIView):
 | 
			
		||||
 | 
			
		||||
    """
 | 
			
		||||
    Calls Django Auth SetPasswordForm save method.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user