Signup: use the get_user_queryset function when checking if user exists.

This commit is contained in:
Tom Hacohen
2020-07-13 16:03:34 +03:00
parent af86d877f2
commit 46b4f08afa
2 changed files with 19 additions and 3 deletions

View File

@@ -394,7 +394,9 @@ class AuthenticationSignupSerializer(serializers.Serializer):
with transaction.atomic():
try:
instance = User.objects.get_by_natural_key(user_data['username'])
view = self.context.get('view', None)
user_queryset = get_user_queryset(User.objects.all(), view)
instance = user_queryset.get(**{User.USERNAME_FIELD: user_data['username'].lower()})
except User.DoesNotExist:
# Create the user and save the casing the user chose as the first name
instance = User.objects.create_user(**user_data, password=None, first_name=user_data['username'])