Пример #1
0
def rlogin():
    email = request.args.get('email')
    onepass = request.args.get('pin')
    if onepass is not None:
        p = executeSQL(
            'select rid from resolvers where remail="%s" and rpin="%s"', True,
            email, onepass)
        if p is not None:
            return Response(response='Success', status=200)
        return Response(response='Failed', status=401)
    else:
        key = otp()
        with cts.app_context():
            msg = Message(
                subject=
                "Single use resolver's pin for NIT Andhra Pradesh CTS login",
                sender=cts.config.get("MAIL_USERNAME"),
                recipients=[email],
                body=
                'Single use pin: "%s" \n \n \n This is an auto generated mail. \n Please do not reply to this message or on this email address. \n For any query, please contact at [email protected] \n Do not disclose any confidential information to anyone.'
                % key)
        mail.send(msg)
        executeSQL('update resolvers set rpin="%s" where remail="%s"', True,
                   key, email)
        return Response(response='Success', status=200)
Пример #2
0
def complaints(cid, token):
    vdata = rvalidate(token)
    exp = request.headers['exp']
    is_resolved = request.headers['is_resolved']  # 0/1
    is_valid = request.headers['is_valid']  # 0/1
    if vdata is not None:
        executeSQL('insert into resolves values(%d, %s, %s, %s,"%s")', False,
                   vdata[0], cid, is_valid, is_resolved, exp)
        return Response(response=json.dumps("success",
                                            indent=4,
                                            sort_keys=True,
                                            default=str),
                        status=200)
    else:
        return Response(response='Failed', status=401)
 def test_getHistoryRowBlock(self):
     # create block
     rollc_before = utils.getMaxIdFromTable(dbHost, dbName, login, pas,
                                            "rollback_tx")
     name = utils.generate_random_name()
     block = "Div(Body: Hello)"
     data = {
         "ApplicationId": "1",
         "Name": name,
         "Value": block,
         "Conditions": "true"
     }
     self.call_contract("NewBlock", data)
     rollc_after = utils.getMaxIdFromTable(dbHost, dbName, login, pas,
                                           "rollback_tx")
     # change block
     id = funcs.get_object_id(url, name, "blocks", token)
     newValueBlock = block.replace("Hello", "new_var")
     data = {"Id": id, "Value": newValueBlock}
     self.call_contract("EditBlock", data)
     # test
     query = """SELECT id FROM "rollback_tx" WHERE table_name = '1_blocks' AND data='' AND id >= %s AND id <= %s""" % (
         rollc_before, rollc_after)
     rollback_id = utils.executeSQL(dbHost, dbName, login, pas, query)[0][0]
     data = {"Table": "blocks", "ID": id, "rID": rollback_id}
     contract = self.contracts["getHistoryRow"]
     self.check_contract_with_data(contract["code"], data, block)
Пример #4
0
def tcomplaints(token):
    vdata = rvalidate(token)
    if vdata is not None:
        data = executeSQL(
            'select * from teachers,complaints, tfiles where teachers.tid=tfiles.tid and tfiles.cid=complaints.cid and tfiles.cid not in (select cid from resolves)',
            False)
        return Response(response=json.dumps(data,
                                            indent=4,
                                            sort_keys=True,
                                            default=str),
                        status=200)
    else:
        return Response(response='Failed', status=401)
Пример #5
0
def myscomplaintsr(token):
    vdata = svalidate(token)
    if vdata is not None:
        data = executeSQL(
            'select * from students,complaints, sfiles, resolves, resolvers where students.sid=sfiles.sid and sfiles.cid=complaints.cid and resolves.cid = complaints.cid and resolves.rid = resolvers.rid and students.sid = %d',
            False, vdata[0])
        return Response(response=json.dumps(data,
                                            indent=4,
                                            sort_keys=True,
                                            default=str),
                        status=200)
    else:
        return Response(response='Failed', status=401)
 def test_getHistoryRowMenu(self):
     # create menu
     rollc_before = utils.getMaxIdFromTable(dbHost, dbName, login, pas,
                                            "rollback_tx")
     name = utils.generate_random_name()
     menu = "This is new menu"
     data = {"Name": name, "Value": menu, "Conditions": "true"}
     self.call_contract("NewMenu", data)
     rollc_after = utils.getMaxIdFromTable(dbHost, dbName, login, pas,
                                           "rollback_tx")
     # change menu
     id = funcs.get_object_id(url, name, "menu", token)
     newValueMenu = menu.replace("new menu", "new_var")
     data = {"Id": id, "Value": newValueMenu}
     self.call_contract("EditMenu", data)
     # test
     query = """SELECT id FROM "rollback_tx" WHERE table_name = '1_menu' AND data='' AND id >= %s AND id <= %s""" % (
         rollc_before, rollc_after)
     rollback_id = utils.executeSQL(dbHost, dbName, login, pas, query)[0][0]
     data = {"Table": "menu", "ID": id, "rID": rollback_id}
     contract = self.contracts["getHistoryRow"]
     self.check_contract_with_data(contract["code"], data, menu)
Пример #7
0
def tfiles(token):
    vdata = tvalidate(token)
    data = request.headers['data']
    tags = request.headers['tags']
    if vdata is not None:
        cid = executeSQL(
            'select cid from complaints where cdata="%s" and tags="%s"', True,
            data, tags)
        if cid is None:
            executeSQL('insert into complaints(cdata,tags) values ("%s","%s")',
                       True, data, tags)
            cid = executeSQL(
                'select cid from complaints where cdata="%s" and tags="%s"',
                True, data, tags)
            time_now = present_date()
            executeSQL(
                'insert into tfiles(tid,cid,ftime) values (%d,%d, "%s")', True,
                vdata[0], cid[0], time_now)
        return Response(response='Success', status=200)
    else:
        return Response(response='Failed', status=401)
Пример #8
0
def slogin():
    email = request.args.get('email')
    onepass = request.args.get('pin')
    try:
        pos = email.index('@')
    except ValueError as e:
        return Response(response='Invalid', status=401)
        pass
    domain = email[pos:]
    if domain != "@student.nitandhra.ac.in":
        return Response(response='Failed', status=401)
    sd = executeSQL('select sid from students where Semail="%s"', True, email)
    print(sd)
    if sd is None:
        executeSQL('insert into students (Semail) values("%s")', True, email)
    if onepass is not None:
        p = executeSQL(
            'select sid from students where Semail="%s" and spin="%s"', True,
            email, onepass)
        if p is not None:
            return Response(response='Success', status=200)
        return Response(response='Failed', status=401)
    else:
        key = otp()
        with cts.app_context():
            msg = Message(
                subject="Single use pin for NIT Andhra Pradesh CTS login",
                sender=cts.config.get("MAIL_USERNAME"),
                recipients=[email],
                body=
                'Single use pin: "%s" \n \n \n This is an auto generated mail. \n Please do not reply to this message or on this email address. \n For any query, please contact at [email protected] \n Do not disclose any confidential information to anyone.'
                % key)
        mail.send(msg)
        executeSQL('update students set spin="%s" where Semail="%s"', True,
                   key, email)
        return Response(response='Success', status=200)
Пример #9
0
def check():
    data = executeSQL(
        'show tables',
        False,
    )
    return Response(response=json.dumps(data), status=200)