Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def create(self, validated_data):
- """Simple response object"""
- user = validated_data['user']
- result = {
- 'balance': user.balance,
- 'consumed': user.consumed,
- 'result': 'authenticated',
- }
- return result
- def validate(self, data):
- """Check that username and password match an existing user"""
- user = authenticate(username=data.get('username'),
- password=data.get('password'))
- if not user:
- raise ValidationError("Provided username and password don't match")
- elif not self.has_credit(user):
- raise ValidationError("Requested user has got no credit")
- else:
- data['user'] = user
- return data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement