Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RegistrationView(APIView):
- """ Allow registration of new users. """
- permission_classes = (permissions.AllowAny,)
- def post(self, request):
- serializer = RegistrationSerializer(data=request.DATA)
- # Check format and unique constraint
- if not serializer.is_valid():
- return Response(serializer.errors,
- status=status.HTTP_400_BAD_REQUEST)
- data = serializer.data
- # u = User.objects.create_user(username=data['username'],
- # email=data['email'],
- # password='password')
- u = User.objects.create(username=data['username'])
- u.set_password(data['password'])
- u.save()
- # Create OAuth2 client
- name = u.username
- client = Client(user=u, name=name, url='' + name,
- client_id=name, client_secret='', client_type=1)
- client.save()
- return Response(serializer.data, status=status.HTTP_201_CREATED)
- REST_FRAMEWORK = {
- 'DEFAULT_AUTHENTICATION_CLASSES':
- ('rest_framework.authentication.OAuth2Authentication',
- 'rest_framework.authentication.SessionAuthentication'),
- 'DEFAULT_MODEL_SERIALIZER_CLASS':
- 'rest_framework.serializers.ModelSerializer',
- 'DEFAULT_PERMISSION_CLASSES':
- ('rest_framework.permissions.IsAdminUser',)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement