Beispiel #1
0
def create_user(request):
    print("create_user")
    pin = request.data['pin']

    queryset = Stock.objects.all()
    queryset = queryset.filter(pin=pin)
    print(len(queryset))
    if(len(queryset) == 1):
        stock = queryset[0]
        print(stock.pin)

        serialized = UserSerializer(data=request.data)
        if serialized.is_valid():
            serialized.save()

            user = auth.authenticate(username=request.data['username'], password=request.data['password']);
            if user is not None:
                tshirt = TShirt(owner=user, message="", color=stock.color, size=stock.size, code=stock.code)
                profile = Profile(owner=user, email=request.data['email'], fullname=request.data['username'])
                banner = MediaFile(owner=user)

                tshirt.save()
                profile.save()
                banner.save()

                stock.delete()

                #test email
                if profile.confReceiveMails == True:
                    send_html_mail('Welcome to DirStuff', 'Welcome to DIRSTUFF', profile.email)
                #end test

            return Response({'response': 'ok'})
        else:
            return Response({'response': 'bad'})
    else:
        serialized = UserSerializer(data=request.data)
        if serialized.is_valid():
            serialized.save()

            user = auth.authenticate(username=request.data['username'], password=request.data['password']);
            if user is not None:
                profile = Profile(owner=user, email=request.data['email'], fullname=request.data['username'])
                banner = MediaFile(owner=user)

                profile.save()
                banner.save()

                #test email
                if profile.confReceiveMails == True:
                    send_html_mail('Welcome to DirStuff', 'Welcome to DIRSTUFF', profile.email)
                #end test

            return Response({'response': 'ok'})
        else:
            return Response({'response': 'bad'})
Beispiel #2
0
 def post(self, request, format=None):
     serializer = UserSerializer(data=request.data,
                                 context={'request': request})
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #3
0
def user_detail_apiview(request, pk, format=None):
    """
    Retrieve, update or delete a user.
    """
    try:
        user = User.objects.get(pk=pk)
    except user.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = UserSerializer(user, context={'request': request})
        return Response(serializer.data)

    elif request.method == 'PUT':
        serializer = UserSerializer(user,
                                    data=request.data,
                                    context={'request': request})
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        user.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Beispiel #4
0
def user_detail_csrf(request, pk, format=None):
    """
    Retrieve, update or delete a user.
    """
    try:
        user = User.objects.get(pk=pk)
    except user.DoesNotExist:
        return HttpResponse(status=404)

    if request.method == 'GET':
        serializer = UserSerializer(user, context={'request': request})
        return JsonResponse(serializer.data)

    elif request.method == 'PUT':
        data = JSONParser().parse(request)
        serializer = UserSerializer(user,
                                    data=data,
                                    context={'request': request})
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors, status=400)

    elif request.method == 'DELETE':
        user.delete()
        return HttpResponse(status=204)
Beispiel #5
0
 def put(self, request, pk, format=None):
     user = self.get_object(pk)
     serializer = UserSerializer(user, data=request.data,context={'request':request})
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #6
0
 def put(self, request, pk, format=None):
     user = self.get_object(pk)
     serializer = UserSerializer(user,
                                 data=request.data,
                                 context={'request': request})
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data)
Beispiel #7
0
def create_auth(request):
    serialized = UserSerializer(data=request.DATA)
    if serialized.is_valid():
        User.objects.create_user(serialized.init_data['email'],
                                 serialized.init_data['username'],
                                 serialized.init_data['password'])
        return Response(serialized.data, status=status.HTTP_201_CREATED)
    else:
        return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #8
0
def user_list(request, format=None):
    if request.method == 'GET':
        user = User.objects.all()
        print(user)
        serializer = UserSerializer(user, many=True)
        return Response(serializer.data, status=status.HTTP_200_OK)
    elif request.method == 'POST':
        serializer = UserSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #9
0
def user_list(request):
    if request.method == "GET":
        users = User.objects.all()
        serializer = UserSerializer(users, many=True)
        return JSONResponse(serializer.data)

    elif request.method == "POST":
        data = JSONParser().parse(request)
        serializer = UserSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Beispiel #10
0
def user_list(request):
    if request.method == 'GET':
        users = User.objects.all()
        serializer = UserSerializer(users, many=True)
        return JSONResponse(serializer.data)
        
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = UserSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Beispiel #11
0
    def put(self, request, pk):
        try:
            user = User.objects.get(pk=pk)
        except User.DoesNotExist:
            return HttpResponse(status=status.HTTP_404_NOT_FOUND)

        if request.user.id != user.id:
            return HttpResponse(status=status.HTTP_403_FORBIDDEN)

        data = JSONParser().parse(request)
        serializer = UserSerializer(user, data=data)
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data)
        return JsonResponse(serializer.errors,
                            status=status.HTTP_400_BAD_REQUEST)
Beispiel #12
0
def user_detail(request, pk, format=None):
    try:
        user = User.objects.get(pk=pk)
    except User.DoesNotExist:
        return Response(status=status.HTTP_400_BAD_REQUEST)

    if request.method == 'GET':
        serilaizer = UserSerializer(user)
        return Response(serilaizer.data, status=status.HTTP_200_OK)
    elif request.method == 'PUT':
        serilaizer = UserSerializer(user, data=request.data)
        if serilaizer.is_valid():
            serilaizer.save()
        return Response(serilaizer.data, status=status.HTTP_200_OK)
    elif request.method == 'DELETE':
        user.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Beispiel #13
0
def user_list_apiview(request, format=None):
    """
    List all users, or create a new user.
    """
    if request.method == 'GET':
        users = User.objects.all()
        serializer = UserSerializer(users,
                                    many=True,
                                    context={'request': request})
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = UserSerializer(data=request.data,
                                    context={'request': request})
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #14
0
def user_list_csrf(request, format=None):
    """
    List all users, or create a new user.
    """
    if request.method == 'GET':
        users = User.objects.all()
        serializer = UserSerializer(users,
                                    many=True,
                                    context={'request': request})
        return JsonResponse(serializer.data, safe=False)

    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = UserSerializer(data=data, context={'request': request})
        if serializer.is_valid():
            serializer.save()
            return JsonResponse(serializer.data, status=201)
        return JsonResponse(serializer.errors, status=400)
def user_list(request, format=None):
    if request.method == 'GET':
        users = User.objects.all()
        serializer = UserSerializer(users, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        role_id = request.data['role_id']
        try:
            role = Role.objects.get(pk=role_id)
        except Role.DoesNotExist:
            return Response('Role(%s) does not exist' % role_id,
                            status=status.HTTP_404_NOT_FOUND)

        print('-----444---> ', request.data)
        # role = Role.objects.get("1")
        # print ('-----55---> ', role);
        serializer = UserSerializer(data=request.data)
        if serializer.is_valid():
            print('====> BEFORE save ', serializer, request)
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #16
0
def user_register(request):
    serializer = UserSerializer(data=request.GET)
    if serializer.is_valid():
        serializer.save()
        return JSONResponse(serializer.data, status=201)
    return JSONResponse(serializer.errors, status=400)
Beispiel #17
0
def user_register(request):
    serializer = UserSerializer(data = request.GET)
    if serializer.is_valid():
        serializer.save()
        return JSONResponse(serializer.data, status=201)
    return JSONResponse(serializer.errors, status=400)