def create(self, **kwargs):
        username = ''

        validated_username = self.validated_data['first_name'].lower() + '.' + self.validated_data['last_name'].lower()
        username_check = User.objects.filter(username=validated_username).count()

        if username_check == 0 and len(validated_username) <= settings.USERNAME_MAX_LENGTH:
            username = validated_username
        else:
            username = get_next_unique_id(User, 'username', validated_username)
            if len(username) > settings.USERNAME_MAX_LENGTH:
                if len(self.validated_data['email']) <= settings.USERNAME_MAX_LENGTH:
                    username = self.validated_data['email']
                else:
                    username = uuid.uuid4().hex[:settings.USERNAME_MAX_LENGTH]

        user = User.objects.create_user(username, self.validated_data.get('email'),
                                        self.initial_data.get('password1'))

        if settings.EMAIL_ENABLED:
            user.is_active = 0
        user.first_name = self.validated_data['first_name']
        user.last_name = self.validated_data['last_name']
        user.save()

        user_profile = models.UserProfile()
        user_profile.user = user
        user_profile.save()

        user_preferences = models.UserPreferences()
        user_preferences.user = user
        user_preferences.save()

        user_financial_account = models.FinancialAccount()
        user_financial_account.owner = user_profile
        user_financial_account.type = 'general'
        user_financial_account.save()

        if self.validated_data.get('is_requester', True):
            requester = models.Requester()
            requester.profile = user_profile
            requester.alias = username
            requester.save()

            requester_financial_account = models.FinancialAccount()
            requester_financial_account.owner = user_profile
            requester_financial_account.type = 'requester'
            requester_financial_account.save()

        has_profile_info = self.validated_data.get('is_requester', False) or self.validated_data.get('is_worker',
                                                                                                     False)

        if self.validated_data.get('is_worker', False) or not has_profile_info:
            worker = models.Worker()
            worker.profile = user_profile
            worker.alias = username
            worker.save()

            worker_financial_account = models.FinancialAccount()
            worker_financial_account.owner = user_profile
            worker_financial_account.type = 'worker'
            worker_financial_account.save()

        if settings.EMAIL_ENABLED:
            salt = hashlib.sha1(str(random.random()).encode('utf-8')).hexdigest()[:5]
            if isinstance(username, str):
                username = username.encode('utf-8')
            activation_key = hashlib.sha1(salt.encode('utf-8') + username).hexdigest()
            registration_model = models.RegistrationModel()
            registration_model.user = User.objects.get(id=user.id)
            registration_model.activation_key = activation_key
            send_activation_email(email=user.email, host=self.context['request'].get_host(),
                                  activation_key=activation_key)
            registration_model.save()
        return user
dataset/ETHPy150Open crowdresearch/crowdsource-platform/crowdsourcing/serializers/user.py/UserSerializer.create/original