def __init__(self): """Adds arguements to the request. Verify a user's key, and connects to the database.""" password = Database.getPassword() parser = reqparse.RequestParser() parser.add_argument("con1", type=str) parser.add_argument("key", type=str, location="headers") parser.add_argument("user", type=str, location="headers") self.parsed = parser.parse_args() key, user = self.parsed["key"], self.parsed["user"] if key == None or user == None: abort(406, message="Either the key, or user field is left blank.") Key().verifyKey(user, key) """A redirect table of some sort is needed. Refer to testing.redirect for a guide.""" try: self.conn, self.cursor = Database.connect("localhost", "root", password[0], "testing") self.schema = "testing" except Exception: self.conn, self.cursor = Database.connect("localhost", "root", password[1], "tsc_office") self.schema = "tsc_office"
def __init__(self): """Handles initialization, connects to database""" password = Database().getPassword() self.schema = "testing" parser = reqparse.RequestParser() parser.add_argument("user", type=str, location="headers") parser.add_argument("key", type=str, location="headers") parser.add_argument("change", type=str) parser.add_argument("previous", type=str) self.parsed = parser.parse_args() user, key = self.parsed["user"], self.parsed["key"] """Verify user""" K = Key() K.verifyKey(user, key) try: self.conn, self.cursor = Database().connect( "localhost", "root", password[0], self.schema) except Exception: self.conn, self.cursor = Database().connect( "localhost", "root", password[1], self.schema)
def __init__(self): """ Handles initilization, and connects to a MySQL database on the server, as well as, a local SQLite database. """ password = Database().getPassword() try: self.sqlConn, self.sqlCursor = Database.connect( "localhost", "root", password[0], self.schema) self.schema = "testing" self.table = "trans" except TYPE_INTERFACE_ERROR: self.sqlConn, self.sqlCursor = Database().connect( "localhost", "root", password[1], "tsc_office") self.schema = "tsc_office" self.table = "" """ These are the arguments the Sync endpoint will accept. If a request is sent through postman (Google it if you don't know what it is), it doesn't matter if its from the 'Params' tab or a 'Body' tab. The only difference is the parameters will show up in the url if you choose 'Params', and it won't shop up if you choose 'Body' """ parser = reqparse.RequestParser() parser.add_argument("key", type=str, location='headers') parser.add_argument("user", type=str, location='headers') parsed = parser.parse_args() key, user = parsed["key"], parsed["user"] verified = Key().verifyKey(user, key) # add key, user abort(406, message="Invalid credentials", code=406, inside="sync.py") if verified == False else "" try: sqliteDb = "env-api\\endpoints\\databases\\syncDb.db" # Path to the local SQLite database stored in the device. self.liteCon = sqlite3.connect(sqliteDb) print("connecting to sqlite3") os.chdir("..\\env-api\\endpoints\\databases") PATH = os.getcwd() + "\\syncDb.db" self.liteCon = sqlite3.connect(PATH) self.liteCursor = self.liteCon.cursor() except FileNotFoundError as e: error = e.strerror abort(400, message=f"{error}. One should be created now. Try again.")
def __init__(self): password = Database.getPassword() self.schema = "tsc_office" try: self.conn, self.cursor = Database.connect("localhost", "root", password[0], self.schema) except Exception: self.conn, self.cursor = Database.connect("localhost", "root", password[1], self.schema) parser = reqparse.RequestParser() parser.add_argument("key", type=str, location='headers') parser.add_argument("user", type=str, location='headers') parsed = parser.parse_args() key, user = parsed["key"], parsed["user"] Key().verifyKey(user, key)
def __init__(self): """Handles initilization, and connects to a MySQL database.""" self.schema = "tsc_office" try: self.mydb, self.cursor = Database().connect("localhost", "root", "YJH030412yjh_g", self.schema) except ProgrammingError: self.mydb, self.cursor = Database().connect("localhost", "root", "8811967", self.schema) # abort(503, message="Unable to connect to database.") parser = reqparse.RequestParser() parser.add_argument("key", type=str, location='headers') parser.add_argument("user", type=str, location='headers') parsed = parser.parse_args() key, user = parsed["key"], parsed["user"] verified = Key().verifyKey(user, key) abort(404, message="Invalid credentials.") if verified == False else ""
def get(self, user, password): """Processes the GET request --- # Parameters ### user The name of the user ### password The user's passowrd """ enc, k = Key().getKey(user, password) sqlString = f"SELECT * FROM tsc_office.tap WHERE fuser = '******' AND fpassword = '******'" self.cursor.execute(sqlString) fid = self.cursor.fetchall()[0][4] return {"fid": fid, "key": k}
def __init__(self): """Handles initialization and connects to a MySQL database.""" password = Database().getPassword() try: self.conn, self.cursor = Database.connect("localhost", "root", password[0], "testing") self.schema = "testing" except Exception: self.conn, self.cursor = Database.connect("localhost", "root", password[1], "tsc_office") self.schema = "tsc_office" parser = reqparse.RequestParser() parser.add_argument("key", type=str, location="headers") parser.add_argument("user", type=str, location="headers") parsed = parser.parse_args() key, user = parsed["key"], parsed["user"] Key().verifyKey(user, key) self.BASE_QUERY = f"SELECT * FROM {self.schema}.spec" """