User: make username case insensitive (and save original styling).
We want 'User' and 'UsEr' to mean the same user. Apparently that's not the default in django. This normalizes the user to ensure we enforce this.
This commit is contained in:
@@ -382,7 +382,12 @@ class AuthenticationSignupSerializer(serializers.Serializer):
|
||||
user_data = validated_data.pop('user')
|
||||
|
||||
with transaction.atomic():
|
||||
instance, _ = User.objects.get_or_create(**user_data)
|
||||
try:
|
||||
instance = User.objects.get_by_natural_key(user_data['username'])
|
||||
except User.DoesNotExist:
|
||||
# Create the user and save the casing the user chose as the first name
|
||||
instance = User.objects.create_user(**user_data, first_name=user_data['username'])
|
||||
|
||||
if hasattr(instance, 'userinfo'):
|
||||
raise serializers.ValidationError('User already exists')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user