Advertisement
Guest User

Untitled

a guest
May 10th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. class RegistrationView(APIView):
  2. """ Allow registration of new users. """
  3. permission_classes = (permissions.AllowAny,)
  4.  
  5. def post(self, request):
  6. serializer = RegistrationSerializer(data=request.DATA)
  7. # Check format and unique constraint
  8. if not serializer.is_valid():
  9. return Response(serializer.errors,
  10. status=status.HTTP_400_BAD_REQUEST)
  11. data = serializer.data
  12.  
  13. # u = User.objects.create_user(username=data['username'],
  14. # email=data['email'],
  15. # password='password')
  16.  
  17. u = User.objects.create(username=data['username'])
  18. u.set_password(data['password'])
  19. u.save()
  20.  
  21. # Create OAuth2 client
  22. name = u.username
  23. client = Client(user=u, name=name, url='' + name,
  24. client_id=name, client_secret='', client_type=1)
  25. client.save()
  26. return Response(serializer.data, status=status.HTTP_201_CREATED)
  27.  
  28. REST_FRAMEWORK = {
  29.  
  30. 'DEFAULT_AUTHENTICATION_CLASSES':
  31. ('rest_framework.authentication.OAuth2Authentication',
  32. 'rest_framework.authentication.SessionAuthentication'),
  33.  
  34. 'DEFAULT_MODEL_SERIALIZER_CLASS':
  35. 'rest_framework.serializers.ModelSerializer',
  36.  
  37. 'DEFAULT_PERMISSION_CLASSES':
  38. ('rest_framework.permissions.IsAdminUser',)
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement