From 177c82ae715619ce5578d1c886ea8aa2682dfe1b Mon Sep 17 00:00:00 2001 From: kdzch Date: Sun, 24 Sep 2017 20:27:57 -0500 Subject: [PATCH 1/5] Update serializers.py first_name and last_name required or not required --- rest_auth/registration/serializers.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rest_auth/registration/serializers.py b/rest_auth/registration/serializers.py index c6b5d5b..b363516 100644 --- a/rest_auth/registration/serializers.py +++ b/rest_auth/registration/serializers.py @@ -127,6 +127,8 @@ class RegisterSerializer(serializers.Serializer): email = serializers.EmailField(required=allauth_settings.EMAIL_REQUIRED) password1 = serializers.CharField(write_only=True) password2 = serializers.CharField(write_only=True) + first_name = serializers.CharField(required=settings.ACCOUNT_FIRST_NAME_REQUIRED, max_length=30) + last_name = serializers.CharField(required=settings.ACCOUNT_LAST_NAME_REQUIRED, max_length=30) def validate_username(self, username): username = get_adapter().clean_username(username) @@ -153,10 +155,12 @@ class RegisterSerializer(serializers.Serializer): def get_cleaned_data(self): return { - 'username': self.validated_data.get('username', ''), - 'password1': self.validated_data.get('password1', ''), - 'email': self.validated_data.get('email', '') - } + 'username': self.validated_data.get('username', ''), + 'password1': self.validated_data.get('password1', ''), + 'email': self.validated_data.get('email', ''), + 'first_name': self.validated_data.get('first_name', ''), + 'last_name': self.validated_data.get('last_name', ''), + } def save(self, request): adapter = get_adapter() From e6d1077ae225bb53758243a688c097d20b926708 Mon Sep 17 00:00:00 2001 From: kdzch Date: Sun, 24 Sep 2017 20:32:02 -0500 Subject: [PATCH 2/5] Update serializers.py error ident --- rest_auth/registration/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_auth/registration/serializers.py b/rest_auth/registration/serializers.py index b363516..ce32c38 100644 --- a/rest_auth/registration/serializers.py +++ b/rest_auth/registration/serializers.py @@ -128,7 +128,7 @@ class RegisterSerializer(serializers.Serializer): password1 = serializers.CharField(write_only=True) password2 = serializers.CharField(write_only=True) first_name = serializers.CharField(required=settings.ACCOUNT_FIRST_NAME_REQUIRED, max_length=30) - last_name = serializers.CharField(required=settings.ACCOUNT_LAST_NAME_REQUIRED, max_length=30) + last_name = serializers.CharField(required=settings.ACCOUNT_LAST_NAME_REQUIRED, max_length=30) def validate_username(self, username): username = get_adapter().clean_username(username) From 602c764a2304396405493895907e1c39aa9b2c4f Mon Sep 17 00:00:00 2001 From: Usuario Date: Sun, 24 Sep 2017 20:59:06 -0500 Subject: [PATCH 3/5] Authentication with email --- rest_auth/serializers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index ca34ccd..9ae1dc2 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -25,7 +25,12 @@ class LoginSerializer(serializers.Serializer): user = None if email and password: - user = authenticate(email=email, password=password) + try: + username = UserModel.objects.get(email__iexact=email).get_username() + user = authenticate(username=username, password=password) + except UserModel.DoesNotExist: + msg = _('Unable to log in with provided credentials.') + raise exceptions.ValidationError(msg) else: msg = _('Must include "email" and "password".') raise exceptions.ValidationError(msg) @@ -47,7 +52,12 @@ class LoginSerializer(serializers.Serializer): user = None if email and password: - user = authenticate(email=email, password=password) + try: + username = UserModel.objects.get(email__iexact=email).get_username() + user = authenticate(username=username, password=password) + except UserModel.DoesNotExist: + msg = _('Unable to log in with provided credentials.') + raise exceptions.ValidationError(msg) elif username and password: user = authenticate(username=username, password=password) else: From ed8961e3c44569ddcf2044105255b86eb5cdf788 Mon Sep 17 00:00:00 2001 From: Usuario Date: Sun, 24 Sep 2017 20:59:43 -0500 Subject: [PATCH 4/5] Error authentication with email --- rest_auth/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index 9ae1dc2..32f4de3 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -81,7 +81,7 @@ class LoginSerializer(serializers.Serializer): user = self._validate_email(email, password) # Authentication through username - if app_settings.AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME: + elif app_settings.AUTHENTICATION_METHOD == app_settings.AuthenticationMethod.USERNAME: user = self._validate_username(username, password) # Authentication through either username or email From 703954f590dd45d3d218b3ac49e36987e3e95045 Mon Sep 17 00:00:00 2001 From: Usuario Date: Sun, 24 Sep 2017 21:08:16 -0500 Subject: [PATCH 5/5] urls of allauth need --- rest_auth/urls.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rest_auth/urls.py b/rest_auth/urls.py index 7a35e9b..66fdb69 100644 --- a/rest_auth/urls.py +++ b/rest_auth/urls.py @@ -5,7 +5,17 @@ from rest_auth.views import ( PasswordResetView, PasswordResetConfirmView ) +from rest_framework import status +from rest_framework.decorators import api_view +from rest_framework.response import Response + +@api_view() +def null_view(request): + return Response(status=status.HTTP_400_BAD_REQUEST) + urlpatterns = [ + url(r'^password-reset-confirm/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', null_view ,name='password_reset_confirm'), + url(r"^confirm-email/$", null_view, name="account_email_verification_sent"), # URLs that do not require a session or valid token url(r'^password/reset/$', PasswordResetView.as_view(), name='rest_password_reset'),