Fix signup and let signup to an empty account.

This commit is contained in:
Tom Hacohen 2020-05-18 16:13:48 +03:00
parent bced00dc8a
commit bd1d11fe5f

View File

@ -219,12 +219,17 @@ class AuthenticationSignupSerializer(serializers.Serializer):
def create(self, validated_data):
"""Function that's called when this serializer creates an item"""
user_data = validated_data.pop('user')
salt = validated_data.pop('salt')
pubkey = validated_data.pop('pubkey')
with transaction.atomic():
instance = User.objects.create(**validated_data)
instance = User.objects.get_or_create(**user_data)
if hasattr(instance, 'userinfo'):
raise serializers.ValidationError('User already exists')
instance.set_unusable_password()
# FIXME: send email verification
models.UserInfo.objects.create(salt=salt, pubkey=pubkey, owner=instance)