diff --git a/rest_auth/registration/serializers.py b/rest_auth/registration/serializers.py index 4f99c182..933bc32a 100644 --- a/rest_auth/registration/serializers.py +++ b/rest_auth/registration/serializers.py @@ -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 @@ def get_social_login(self, adapter, app, token, response): `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 @@ def validate(self, attrs): 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 @@ def validate(self, attrs): 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 @@ def get_social_login(self, *args, **kwargs): 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 @@ def validate_password1(self, password): 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): diff --git a/rest_auth/registration/urls.py b/rest_auth/registration/urls.py index 1004695e..071c2e5c 100644 --- a/rest_auth/registration/urls.py +++ b/rest_auth/registration/urls.py @@ -1,11 +1,11 @@ from django.views.generic import TemplateView -from django.conf.urls import url +from django.urls import path, re_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 @@ # 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[-:\w]+)/$', TemplateView.as_view(), - name='account_confirm_email'), + re_path(r'account-confirm-email/(?P[-:\w]+)/', TemplateView.as_view(), + name='account_confirm_email'), ] diff --git a/rest_auth/registration/views.py b/rest_auth/registration/views.py index 0e0ab0d0..bab1c1c4 100644 --- a/rest_auth/registration/views.py +++ b/rest_auth/registration/views.py @@ -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 diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index b6452317..e180d277 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -3,8 +3,8 @@ 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 @@ def validate(self, attrs): # 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 @@ def validate(self, attrs): 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 @@ def get_user(self, obj): """ 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 @@ def get_email_options(self): 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 @@ def validate(self, attrs): # 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 @@ def validate_old_password(self, value): ) 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): diff --git a/rest_auth/tests/urls.py b/rest_auth/tests/urls.py index 401f23a6..3be5113b 100644 --- a/rest_auth/tests/urls.py +++ b/rest_auth/tests/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url, include +from django.urls import path, re_path, include from django.views.generic import TemplateView from . import django_urls @@ -53,20 +53,20 @@ class TwitterLoginNoAdapter(SocialLoginView): urlpatterns += [ - url(r'^rest-registration/', include('rest_auth.registration.urls')), - url(r'^test-admin/', include(django_urls)), - url(r'^account-email-verification-sent/$', TemplateView.as_view(), + path('rest-registration/', include('rest_auth.registration.urls')), + path('test-admin/', include(django_urls)), + re_path(r'^account-email-verification-sent/$', TemplateView.as_view(), name='account_email_verification_sent'), - url(r'^account-confirm-email/(?P[-:\w]+)/$', TemplateView.as_view(), + re_path(r'^account-confirm-email/(?P[-:\w]+)/$', TemplateView.as_view(), name='account_confirm_email'), - url(r'^social-login/facebook/$', FacebookLogin.as_view(), name='fb_login'), - 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'), - 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'), - url(r'^socialaccounts/(?P\d+)/disconnect/$', SocialAccountDisconnectView.as_view(), + re_path(r'^social-login/facebook/$', FacebookLogin.as_view(), name='fb_login'), + re_path(r'^social-login/twitter/$', TwitterLogin.as_view(), name='tw_login'), + re_path(r'^social-login/twitter-no-view/$', twitter_login_view, name='tw_login_no_view'), + re_path(r'^social-login/twitter-no-adapter/$', TwitterLoginNoAdapter.as_view(), name='tw_login_no_adapter'), + re_path(r'^social-login/facebook/connect/$', FacebookConnect.as_view(), name='fb_connect'), + re_path(r'^social-login/twitter/connect/$', TwitterConnect.as_view(), name='tw_connect'), + re_path(r'^socialaccounts/$', SocialAccountListView.as_view(), name='social_account_list'), + re_path(r'^socialaccounts/(?P\d+)/disconnect/$', SocialAccountDisconnectView.as_view(), name='social_account_disconnect'), - url(r'^accounts/', include('allauth.socialaccount.urls')) + path('accounts/', include('allauth.socialaccount.urls')) ] diff --git a/rest_auth/urls.py b/rest_auth/urls.py index 7a35e9b5..e74d138f 100644 --- a/rest_auth/urls.py +++ b/rest_auth/urls.py @@ -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 @@ 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'), ] diff --git a/rest_auth/views.py b/rest_auth/views.py index 0a0a982e..88c69f14 100644 --- a/rest_auth/views.py +++ b/rest_auth/views.py @@ -6,7 +6,7 @@ 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 @@ def get_response(self): 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,