Exemplo n.º 1
0
    def post(self, request):
        """
        Create a new User
        """

        serializer = UserWithPasswordSerializer(data=request.DATA)
        if serializer.is_valid():
            user = serializer.save()
            if 'password' in request.DATA:
                password = request.DATA['password']
                user.set_password(password)
                user.save()

                try:
                    # create SLA provider (SLA module)
                    if user.groups.filter(name__in=['Service Provider', 'Function Provider']).exists():
                        #sla_response = requests.post('http://sla.docker:9040/providers', auth=('user', 'password'), json={"uuid": user.id, "name": user.username})
                        sla_response = requests.post('http://sla.docker:9040/providers', auth=('user', 'password'), json={"uuid": user.username, "name": user.username})
                        if sla_response.status_code == 201:
                            print 'SLA provider created %s-%s' % (user.id, user.username)
                        else:
                            print 'SLA provider creation failed %s-%s' % (user.id, user.username)
                except:
                    print 'SLA provider creation failed %s-%s' % (user.id, user.username)

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
    def post(self, request):
        """
        Create a new User
        """

        serializer = UserWithPasswordSerializer(data=request.DATA)
        if serializer.is_valid():
            user = serializer.save()
            if "password" in request.DATA:
                password = request.DATA["password"]
                user.set_password(password)
                user.save()

                try:
                    # create SLA provider (SLA module)
                    if user.groups.filter(name__in=["Service Provider", "Function Provider"]).exists():
                        sla_response = requests.post(
                            "http://sla.docker:9040/providers",
                            auth=("user", "password"),
                            json={"uuid": user.id, "name": user.username},
                        )
                        if sla_response.status_code == 201:
                            print "SLA provider created %s-%s" % (user.id, user.username)
                        else:
                            print "SLA provider creation failed %s-%s" % (user.id, user.username)
                except:
                    print "SLA provider creation failed %s-%s" % (user.id, user.username)

            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
 def patch(self, request, pk):
     user = self.get_object(pk)
     if request.user.has_perm('umaa.edit_user') or request.user == user:
         serializer = UserWithPasswordSerializer(user, data=request.DATA, partial=True)
         if serializer.is_valid():
             serializer.save()
             if 'password' in request.DATA:
                 password = request.DATA['password']
                 user.set_password(password)
                 user.save()
             return Response(serializer.data, status=status.HTTP_200_OK)
         else:
             return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(UNAUTHORIZED_MSG, status=status.HTTP_401_UNAUTHORIZED)
Exemplo n.º 4
0
 def patch(self, request, pk):
     user = self.get_object(pk)
     if request.user.has_perm("umaa.edit_user") or request.user == user:
         serializer = UserWithPasswordSerializer(user, data=request.DATA, partial=True)
         if serializer.is_valid():
             serializer.save()
             if "password" in request.DATA:
                 password = request.DATA["password"]
                 user.set_password(password)
                 user.save()
             return Response(serializer.data, status=status.HTTP_200_OK)
         else:
             return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(UNAUTHORIZED_MSG, status=status.HTTP_401_UNAUTHORIZED)