Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AccountSerializer(serializers.ModelSerializer):
- """
- Account Serializer
- """
- class Meta:
- model = models.Account
- fields = (
- 'id', 'email', 'name', 'birthdate', 'phone_number', 'gender',
- 'facebook', 'twitter', 'instagram', 'avatar', 'has_usable_password',
- 'has_confirmed_terms', 'created_at', 'updated_at'
- )
- read_only_fields = ('created_at', 'updated_at')
- extra_kwargs = {'has_confirmed_terms': {'write_only': True}}
- def create(self, validated_data):
- password = self.context['request'].data.get('password')
- if not password:
- raise serializers.ValidationError({'password': [_('This field is required.')]})
- if not validated_data.get('has_confirmed_terms', False):
- raise serializers.ValidationError({'has_confirmed_terms': [_('This field is required.')]})
- account = models.Account.objects.create_user(
- password=password,
- **validated_data
- )
- account.save()
- campaign_new_user.delay(account.pk)
- auth = authenticate(username=account.username, password=password)
- login(self.context['request'], auth)
- return account
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement