mirror of
				https://github.com/Tivix/django-rest-auth.git
				synced 2025-10-30 23:37:32 +03:00 
			
		
		
		
	made compatible with django-4.0
This commit is contained in:
		
							parent
							
								
									3c36004c44
								
							
						
					
					
						commit
						1e760cbef9
					
				|  | @ -1,5 +1,5 @@ | |||
| from django.http import HttpRequest | ||||
| from django.utils.translation import ugettext_lazy as _ | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| from django.contrib.auth import get_user_model | ||||
| 
 | ||||
| try: | ||||
|  | @ -54,7 +54,8 @@ class SocialLoginSerializer(serializers.Serializer): | |||
|             `allauth.socialaccount.SocialLoginView` instance | ||||
|         """ | ||||
|         request = self._get_request() | ||||
|         social_login = adapter.complete_login(request, app, token, response=response) | ||||
|         social_login = adapter.complete_login( | ||||
|             request, app, token, response=response) | ||||
|         social_login.token = token | ||||
|         return social_login | ||||
| 
 | ||||
|  | @ -69,7 +70,8 @@ class SocialLoginSerializer(serializers.Serializer): | |||
| 
 | ||||
|         adapter_class = getattr(view, 'adapter_class', None) | ||||
|         if not adapter_class: | ||||
|             raise serializers.ValidationError(_("Define adapter_class in view")) | ||||
|             raise serializers.ValidationError( | ||||
|                 _("Define adapter_class in view")) | ||||
| 
 | ||||
|         adapter = adapter_class(request) | ||||
|         app = adapter.get_provider().get_app(request) | ||||
|  | @ -119,7 +121,8 @@ class SocialLoginSerializer(serializers.Serializer): | |||
|         social_token.app = app | ||||
| 
 | ||||
|         try: | ||||
|             login = self.get_social_login(adapter, app, social_token, access_token) | ||||
|             login = self.get_social_login( | ||||
|                 adapter, app, social_token, access_token) | ||||
|             complete_social_login(request, login) | ||||
|         except HTTPError: | ||||
|             raise serializers.ValidationError(_("Incorrect value")) | ||||
|  | @ -154,7 +157,8 @@ class SocialConnectMixin(object): | |||
|         Refer to the implementation of get_social_login in base class and to the | ||||
|         allauth.socialaccount.helpers module complete_social_login function. | ||||
|         """ | ||||
|         social_login = super(SocialConnectMixin, self).get_social_login(*args, **kwargs) | ||||
|         social_login = super(SocialConnectMixin, | ||||
|                              self).get_social_login(*args, **kwargs) | ||||
|         social_login.state['process'] = AuthProcess.CONNECT | ||||
|         return social_login | ||||
| 
 | ||||
|  | @ -190,7 +194,8 @@ class RegisterSerializer(serializers.Serializer): | |||
| 
 | ||||
|     def validate(self, data): | ||||
|         if data['password1'] != data['password2']: | ||||
|             raise serializers.ValidationError(_("The two password fields didn't match.")) | ||||
|             raise serializers.ValidationError( | ||||
|                 _("The two password fields didn't match.")) | ||||
|         return data | ||||
| 
 | ||||
|     def custom_signup(self, request, user): | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| from django.views.generic import TemplateView | ||||
| from django.conf.urls import url | ||||
| from django.urls import path | ||||
| 
 | ||||
| from .views import RegisterView, VerifyEmailView | ||||
| 
 | ||||
| urlpatterns = [ | ||||
|     url(r'^$', RegisterView.as_view(), name='rest_register'), | ||||
|     url(r'^verify-email/$', VerifyEmailView.as_view(), name='rest_verify_email'), | ||||
|     path('', RegisterView.as_view(), name='rest_register'), | ||||
|     path('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 | ||||
|  | @ -18,6 +18,6 @@ urlpatterns = [ | |||
|     # If you don't want to use API on that step, then just use ConfirmEmailView | ||||
|     # view from: | ||||
|     # django-allauth https://github.com/pennersr/django-allauth/blob/master/allauth/account/views.py | ||||
|     url(r'^account-confirm-email/(?P<key>[-:\w]+)/$', TemplateView.as_view(), | ||||
|         name='account_confirm_email'), | ||||
|     path('account-confirm-email/(?P<key>[-:\w]+)/', TemplateView.as_view(), | ||||
|          name='account_confirm_email'), | ||||
| ] | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| from django.conf import settings | ||||
| from django.utils.decorators import method_decorator | ||||
| from django.utils.translation import ugettext_lazy as _ | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| from django.views.decorators.debug import sensitive_post_parameters | ||||
| 
 | ||||
| from rest_framework.views import APIView | ||||
|  |  | |||
|  | @ -3,8 +3,8 @@ from django.conf import settings | |||
| from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm | ||||
| from django.contrib.auth.tokens import default_token_generator | ||||
| from django.utils.http import urlsafe_base64_decode as uid_decoder | ||||
| from django.utils.translation import ugettext_lazy as _ | ||||
| from django.utils.encoding import force_text | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| from django.utils.encoding import force_str | ||||
| 
 | ||||
| from rest_framework import serializers, exceptions | ||||
| from rest_framework.exceptions import ValidationError | ||||
|  | @ -85,7 +85,8 @@ class LoginSerializer(serializers.Serializer): | |||
|             # Authentication without using allauth | ||||
|             if email: | ||||
|                 try: | ||||
|                     username = UserModel.objects.get(email__iexact=email).get_username() | ||||
|                     username = UserModel.objects.get( | ||||
|                         email__iexact=email).get_username() | ||||
|                 except UserModel.DoesNotExist: | ||||
|                     pass | ||||
| 
 | ||||
|  | @ -107,7 +108,8 @@ class LoginSerializer(serializers.Serializer): | |||
|             if app_settings.EMAIL_VERIFICATION == app_settings.EmailVerificationMethod.MANDATORY: | ||||
|                 email_address = user.emailaddress_set.get(email=user.email) | ||||
|                 if not email_address.verified: | ||||
|                     raise serializers.ValidationError(_('E-mail is not verified.')) | ||||
|                     raise serializers.ValidationError( | ||||
|                         _('E-mail is not verified.')) | ||||
| 
 | ||||
|         attrs['user'] = user | ||||
|         return attrs | ||||
|  | @ -147,9 +149,11 @@ class JWTSerializer(serializers.Serializer): | |||
|         """ | ||||
|         rest_auth_serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {}) | ||||
|         JWTUserDetailsSerializer = import_callable( | ||||
|             rest_auth_serializers.get('USER_DETAILS_SERIALIZER', UserDetailsSerializer) | ||||
|             rest_auth_serializers.get( | ||||
|                 'USER_DETAILS_SERIALIZER', UserDetailsSerializer) | ||||
|         ) | ||||
|         user_data = JWTUserDetailsSerializer(obj['user'], context=self.context).data | ||||
|         user_data = JWTUserDetailsSerializer( | ||||
|             obj['user'], context=self.context).data | ||||
|         return user_data | ||||
| 
 | ||||
| 
 | ||||
|  | @ -167,7 +171,8 @@ class PasswordResetSerializer(serializers.Serializer): | |||
| 
 | ||||
|     def validate_email(self, value): | ||||
|         # Create PasswordResetForm with the serializer | ||||
|         self.reset_form = self.password_reset_form_class(data=self.initial_data) | ||||
|         self.reset_form = self.password_reset_form_class( | ||||
|             data=self.initial_data) | ||||
|         if not self.reset_form.is_valid(): | ||||
|             raise serializers.ValidationError(self.reset_form.errors) | ||||
| 
 | ||||
|  | @ -205,7 +210,7 @@ class PasswordResetConfirmSerializer(serializers.Serializer): | |||
| 
 | ||||
|         # Decode the uidb64 to uid to get User object | ||||
|         try: | ||||
|             uid = force_text(uid_decoder(attrs['uid'])) | ||||
|             force_str(uid_decoder(attrs['uid'])) | ||||
|             self.user = UserModel._default_manager.get(pk=uid) | ||||
|         except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): | ||||
|             raise ValidationError({'uid': ['Invalid value']}) | ||||
|  | @ -256,8 +261,7 @@ class PasswordChangeSerializer(serializers.Serializer): | |||
|         ) | ||||
| 
 | ||||
|         if all(invalid_password_conditions): | ||||
|             err_msg = _("Your old password was entered incorrectly. Please enter it again.") | ||||
|             raise serializers.ValidationError(err_msg) | ||||
|             raise serializers.ValidationError('Invalid password') | ||||
|         return value | ||||
| 
 | ||||
|     def validate(self, attrs): | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| from django.conf.urls import url | ||||
| from django.urls import path | ||||
| 
 | ||||
| from rest_auth.views import ( | ||||
|     LoginView, LogoutView, UserDetailsView, PasswordChangeView, | ||||
|  | @ -7,14 +7,14 @@ from rest_auth.views import ( | |||
| 
 | ||||
| urlpatterns = [ | ||||
|     # URLs that do not require a session or valid token | ||||
|     url(r'^password/reset/$', PasswordResetView.as_view(), | ||||
|         name='rest_password_reset'), | ||||
|     url(r'^password/reset/confirm/$', PasswordResetConfirmView.as_view(), | ||||
|         name='rest_password_reset_confirm'), | ||||
|     url(r'^login/$', LoginView.as_view(), name='rest_login'), | ||||
|     path('password/reset/', PasswordResetView.as_view(), | ||||
|          name='rest_password_reset'), | ||||
|     path('password/reset/confirm/', PasswordResetConfirmView.as_view(), | ||||
|          name='rest_password_reset_confirm'), | ||||
|     path('login/', LoginView.as_view(), name='rest_login'), | ||||
|     # URLs that require a user to be logged in with a valid session / token. | ||||
|     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'), | ||||
|     path('logout/', LogoutView.as_view(), name='rest_logout'), | ||||
|     path('user/', UserDetailsView.as_view(), name='rest_user_details'), | ||||
|     path('password/change/', PasswordChangeView.as_view(), | ||||
|          name='rest_password_change'), | ||||
| ] | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ from django.conf import settings | |||
| from django.contrib.auth import get_user_model | ||||
| from django.core.exceptions import ObjectDoesNotExist | ||||
| from django.utils.decorators import method_decorator | ||||
| from django.utils.translation import ugettext_lazy as _ | ||||
| from django.utils.translation import gettext_lazy as _ | ||||
| from django.views.decorators.debug import sensitive_post_parameters | ||||
| 
 | ||||
| from rest_framework import status | ||||
|  | @ -89,7 +89,8 @@ class LoginView(GenericAPIView): | |||
|             from rest_framework_jwt.settings import api_settings as jwt_settings | ||||
|             if jwt_settings.JWT_AUTH_COOKIE: | ||||
|                 from datetime import datetime | ||||
|                 expiration = (datetime.utcnow() + jwt_settings.JWT_EXPIRATION_DELTA) | ||||
|                 expiration = (datetime.utcnow() + | ||||
|                               jwt_settings.JWT_EXPIRATION_DELTA) | ||||
|                 response.set_cookie(jwt_settings.JWT_AUTH_COOKIE, | ||||
|                                     self.token, | ||||
|                                     expires=expiration, | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 sk
						sk