Advertisement
Guest User

Untitled

a guest
Jun 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. def create(self, validated_data):
  2. """Simple response object"""
  3.  
  4. user = validated_data['user']
  5. result = {
  6. 'balance': user.balance,
  7. 'consumed': user.consumed,
  8. 'result': 'authenticated',
  9. }
  10. return result
  11.  
  12. def validate(self, data):
  13. """Check that username and password match an existing user"""
  14.  
  15. user = authenticate(username=data.get('username'),
  16. password=data.get('password'))
  17. if not user:
  18. raise ValidationError("Provided username and password don't match")
  19.  
  20. elif not self.has_credit(user):
  21. raise ValidationError("Requested user has got no credit")
  22.  
  23. else:
  24. data['user'] = user
  25. return data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement