Exemplo n.º 1
0
def signup():
    print(req.json)
    body = req.json
    rows = Users.findAll({'where': {'regno': body['regno']}})
    print(rows)
    if (len(rows) == 0):
        response = res(json.dumps({"message": "User does not exists"}),
                       status=403,
                       mimetype="application/json")
    elif (body['password'] == rows[0][6]):
        payload = req.json.copy()
        payload['timestamp'] = str(time.time())
        payload['exp'] = datetime.datetime.utcnow() + datetime.timedelta(
            seconds=180000)
        token = jwt.encode(payload,
                           "srimanakulavinayagarengineeringcollege-vikram-dl",
                           algorithm='HS256').decode("utf-8")
        response = res(json.dumps({
            "message": "Success",
            "user": rows[0][:-1],
            'token': token
        }),
                       status=200,
                       mimetype="application/json")
        response.set_cookie("token", token, domain="172.20.10.6:*")
    else:
        response = res(json.dumps({"message": "Unauthorized"}),
                       status=403,
                       mimetype="application/json")
    return response
Exemplo n.º 2
0
def signup():
    print(req.json)
    res_code = Users.insert(req.json)
    if (res_code == -1):
        response = res(json.dumps({"message": "Error"}),
                       status=500,
                       mimetype="application/json")
    elif (res_code == -2):
        response = res(json.dumps({"message": "Duplicate"}),
                       status=409,
                       mimetype="application/json")
    else:
        response = res(json.dumps({"message": "Success"}),
                       status=200,
                       mimetype="application/json")
    return response
Exemplo n.º 3
0
def report():
    body = req.json.copy()
    body['report'] = json.dumps(body['report'])
    res_code = Report.insert(body)
    if (res_code == -1):
        response = res(json.dumps({"message": "Error"}),
                       status=500,
                       mimetype="application/json")
    elif (res_code == -2):
        response = res(json.dumps({"message": "Duplicate"}),
                       status=409,
                       mimetype="application/json")
    else:
        response = res(json.dumps({"message": "Success"}),
                       status=200,
                       mimetype="application/json")
    return response
Exemplo n.º 4
0
def CreateTest():
    print(req.json)
    res_code = TestTable.insert(req.json)
    if (res_code == -1):
        response = res(json.dumps({"message": "Error"}),
                       status=500,
                       mimetype="application/json")
    elif (res_code == -2):
        response = res(json.dumps({"message": "Duplicate"}),
                       status=409,
                       mimetype="application/json")
    else:
        os.makedirs('./Tests/{}'.format(req.json.get('name')))
        response = res(json.dumps({"message": "Success"}),
                       status=200,
                       mimetype="application/json")
    return response
Exemplo n.º 5
0
def run():
    # print(req.json)
    message = req.json
    message['isRun'] = True
    print(message)
    producer.send(req.json['lang'], value=json.dumps(message).encode('utf-8'))
    return res(json.dumps({'id':message['id']}), status=200)
    
Exemplo n.º 6
0
def GetQuestion(test_name):
    print(test_name)
    questions = []
    questions_dirs = os.listdir('./Tests/{}'.format(test_name))
    for questions_dir in questions_dirs:
        content = open('./Tests/{}/{}/question.txt'.format(
            test_name, questions_dir))
        questions.append(content.read())
    print(questions)
    return res(json.dumps({'questions': questions}),
               status=200,
               mimetype="application/json")
def upload(test_name):
    questions = req.json['questions']
    for index in range(0,len(questions)):
        question = questions[index]
        os.makedirs('./Tests/{}/{}'.format(test_name, str(index)))
        os.makedirs('./Tests/{}/{}/Testcases'.format(test_name, str(index)))
        with open('./Tests/{}/{}/question.txt'.format(test_name, str(index)), 'w') as fp:
            fp.writelines(question.get('string'))
        testcases = question.get('testcases')
        for i_index in range(0, len(testcases)):
            testcase = testcases[i_index]
            os.makedirs('./Tests/{}/{}/Testcases/{}'.format(test_name, str(index), str(i_index)))
            input_file = open('./Tests/{}/{}/Testcases/{}/input.txt'.format(test_name, str(index), str(i_index)), 'w')
            input_file.writelines(testcase.get('input'))
            output_file = open('./Tests/{}/{}/Testcases/{}/output.txt'.format(test_name, str(index), str(i_index)), 'w')
            output_file.writelines(testcase.get('output'))
    
    return res(status=200)
Exemplo n.º 8
0
def response_to_client(status=HTTP_Status.SUCCESS, data={}):
    return res(data, status.value, mimetype='application/json')
Exemplo n.º 9
0
def ListTest():
    print(req.json)
    rows = TestTable.findAll()
    response = res(json.dumps({"rows":rows}), status=200, mimetype="application/json")
    return response