Exemplo n.º 1
0
 def update(self, request, *args, **kwargs):
     auth_token = request.META.get(HTTP_AUTHORIZATION, '').replace('Token ', '')
     user = Token.objects.get(key=auth_token).user
     user = User.objects.filter(username=user, pk=kwargs['pk'])
     if user:
         user_serializer = UserSerializer(data=request.data)
         user_serializer.is_valid(raise_exception=True)
         user.update(username=request.data['username'],
                              email=request.data['email'],
                              password=request.data['password'])
         return Response({'username': user_serializer.validated_data["username"]}, status=status.HTTP_200_OK)
     else:
         return Response(status=status.HTTP_404_NOT_FOUND)
Exemplo n.º 2
0
 def post(request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save()
         data = dict(status="Success!")
         return Response(data=data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=400)
Exemplo n.º 3
0
 def create(self, request, *args, **kwargs):
     group = Group.objects.filter(name='candidates')
     user_serializer = UserSerializer(data=request.data)
     user_serializer.is_valid(raise_exception=True)
     user = user_serializer.save(groups=group)
     return Response({'id': user.pk}, status=status.HTTP_201_CREATED)