def save(self): # Create the Password Manager password_manager = PasswordManager() # Create the DBConnection database = DBConnection() # Create the SQL if self.id is None: sql = "INSERT INTO connections (name, host, port, user, passwd, use_key, key_path)" \ " VALUES ('{}', '{}', {}, '{}', '{}', {}, '{}');" else: sql = "UPDATE connections SET name = '{}', host = '{}', port = {}, user = '******', passwd = '{}'," \ " use_key = {}, key_path = '{}' where id_connection = {}" # Bind the values sql = sql.format(self.name, self.host, self.port, self.user, password_manager.encrypt_password(self.password), 1 if self.use_key else 0, self.key_path, self.id) # Execute the SQL if database.execute_query(sql) > 0: # Get the last row inserted if self.id is None: self.id = database.cursor.lastrowid # Return true telling it's OK return True else: # Return False for fail return False
def load(self): # Create the Password Manager password_manager = PasswordManager() # Create the DBConnection database = DBConnection() # Create the SQL sql = "SELECT * FROM connections WHERE id_connection = {}" # Bind the value sql = sql.format(self.id) # Execute the query rows = database.select_query(sql) # Set the attrs for row in rows: self.name = row['name'] self.host = row['host'] self.port = row['port'] self.user = row['user'] self.password = password_manager.decrypt_password(row['passwd']) self.use_key = True if int(row['use_key']) == 1 else False self.key_path = row['key_path']
def save(self): # Create the Password Manager password_manager = PasswordManager() # Create the DBConnection database = DBConnection() # Create the SQL if self.id is None: sql = "INSERT INTO connections (name, host, port, user, passwd, use_key, key_path)" \ " VALUES ('{}', '{}', {}, '{}', '{}', {}, '{}');" else: sql = "UPDATE connections SET name = '{}', host = '{}', port = {}, user = '******', passwd = '{}'," \ " use_key = {}, key_path = '{}' where id_connection = {}" # Bind the values sql = sql.format( self.name, self.host, self.port, self.user, password_manager.encrypt_password(self.password), 1 if self.use_key else 0, self.key_path, self.id ) # Execute the SQL if database.execute_query(sql) > 0: # Get the last row inserted if self.id is None: self.id = database.cursor.lastrowid # Return true telling it's OK return True else: # Return False for fail return False