Ejemplo n.º 1
0
def update(request, index1):
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    input = universal.getText(request.body)
    body = input[1]
    if input == False:
        return HttpResponse("ErrorA", status=400)
    if "name" not in body:
        return HttpResponse("ErrorB", status=400)
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    with connection.cursor() as cursor:
        cursor.execute(
            "UPDATE public.game SET name = %s, price = %s, description = %s WHERE id = %s",
            [body["name"], body["price"], body["description"], index1])
    result = "Zaidimas atnaujintas"
    return HttpResponse(result, status=statusCode)
Ejemplo n.º 2
0
def create(request, index1):
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    input = universal.getText(request.body)
    body = input[1]
    if input[0] == False:
        return HttpResponse("ErrorA", status=400)
    if "content" not in body:
        return HttpResponse("ErrorB", status=400)

    statusCode = 201
    with connection.cursor() as cursor:
        cursor.execute(
            "INSERT INTO public.review(game_id,user_id,content) VALUES (%s,%s,%s) RETURNING id, content",
            [index1, body["user_id"], body["content"]])
        returnedId = universal.dictfetchall(cursor)
    result = universal.dumpJson(returnedId)
    return HttpResponse(result,
                        status=statusCode,
                        content_type="application/json")
Ejemplo n.º 3
0
def create(request):
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse (result, content_type, 401)
    else:
        return HttpResponse (result, content_type, 401)  

    input = universal.getText(request.body)
    body = input[1]
    if input[0] == False:
        return HttpResponse ("ErrorA", status = 400)
    if "name" not in body:
        return HttpResponse ("ErrorB", status = 400)

    scope = request.headers["scope"]
    scope = int(scope)
    if scope != 2:
        return HttpResponse("Not admin", content_type, 403)         
    statusCode = 201  
    with connection.cursor() as cursor:
        cursor.execute("INSERT INTO public.category(name) VALUES (%s) RETURNING id, name", [body["name"]])
        returnedId = universal.dictfetchall(cursor)
    result = universal.dumpJson(returnedId)
    return HttpResponse (result, status = statusCode, content_type = "application/json")
Ejemplo n.º 4
0
def update(request, index1, index2):
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    input = universal.getText(request.body)
    body = input[1]
    if input == False:
        return HttpResponse("ErrorA", status=400)
    if "content" not in body:
        return HttpResponse("ErrorB", status=400)
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    with connection.cursor() as cursor:
        cursor.execute("UPDATE public.review SET content = %s WHERE id = %s",
                       [body["content"], index2])
    result = "Apzvalga atnaujinta"
    return HttpResponse(result, status=statusCode)
Ejemplo n.º 5
0
def update(request, index1):
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    input = universal.getText(request.body)
    body = input[1]
    if input == False:
        return HttpResponse("ErrorA", status=400)
    if "username" not in body:
        return HttpResponse("ErrorB", status=400)
    statusCode = 200
    result = "bad"
    content_type = None

    if "Authorization" in request.headers:
        auth = universal.decode_token(request.headers["Authorization"])
        if auth[0] == False:
            return HttpResponse(result, content_type, 401)
    else:
        return HttpResponse(result, content_type, 401)

    hashedPass = make_password(body["password"])

    with connection.cursor() as cursor:
        cursor.execute(
            "UPDATE public.user SET username = %s, password = %s, role = %s WHERE id = %s",
            [body["username"], hashedPass, body["role"], index1])
    result = "Vartotojas atnaujintas"
    return HttpResponse(result, status=statusCode)