def update(self): '''updates a email on the bd''' result = None mydb = None try: collection = "SignerUser" mydb = ManageDB(collection) temp_user = self.__dict__.copy() has_record_id = getattr(temp_user, "_id", False) if has_record_id: # Exclude the _id from the object since it's going to be updated temp_user.pop("_id") temp_user.pop("priv_key") temp_user.pop("pub_key") result = mydb.update({"email": self.email}, temp_user) except Exception as error: logger.info("updating signer user " + str(error)) result = None finally: if mydb is not None: mydb.close() return result
def create(self): '''creates a new sign record on the bd''' result = False mydb = None try: collection = "SignRecord" mydb = ManageDB(collection) result = mydb.insert_json(self.__dict__) except Exception as error: logger.info("creating sign record", error) finally: if mydb is not None: mydb.close() return result
def get_attribute(self, attribute_name): '''gets the attribute from the bd''' result = False mydb = None try: collection = "SignRecord" mydb = ManageDB(collection) docs = mydb.select("tx_id", self.tx_id) if len(docs) > 0: result = docs[0].get(attribute_name) except: result = None finally: if mydb is not None: mydb.close() return result
def find(self): '''finds a signer user by the tx_id''' result = False mydb = None try: collection = "SignRecord" mydb = ManageDB(collection) docs = mydb.select("tx_id", self.tx_id) if len(docs) > 0: result = True except Exception as e: logger.info("finding sign record "+ str(e)) finally: if mydb is not None: mydb.close() return result
def check(self): '''finds a user''' result = False mydb = None try: collection = DOCUMENT mydb = ManageDB(collection) docs = mydb.select("doc_id", self.doc_id) if len(docs) > 0: result = True except Exception as e: logger.info("finding id"+ str(e)) finally: if mydb is not None: mydb.close() return result
def update(self): '''updates a sign record on the bd''' result = None mydb = None try: collection = "SignRecord" mydb = ManageDB(collection) temp_record = self.__dict__.copy() temp_record.pop("_id") result = mydb.update({"tx_id": self.tx_id}, temp_record) except Exception as error: logger.info("updating sign record "+ str(error)) result = None finally: if mydb is not None: mydb.close() return result
def find_by_attr(self, key, value): '''finds a user object by the attribute id''' result = False mydb = None try: collection = "SignRecord" mydb = ManageDB(collection) docs = mydb.select(key, value) if len(docs) > 0: result = docs else: logger.info("sign record not found") except Exception as e: logger.info("finding sign record" + str(e)) finally: if mydb is not None: mydb.close() return result
def create(self): '''creates a new link on the bd''' result = False mydb = None if self.doc_id is None or self.link is None: return result try: collection = LINK mydb = ManageDB(collection) temp_link = self.__dict__ result = mydb.insert_json(temp_link) except Exception as error: logger.info("creating link " + str(error)) finally: if mydb is not None: mydb.close() return result
def create(self): '''creates a new document on the bd''' result = False mydb = None if self.org_id is None or self.doc_id is None: return result try: collection = DOCUMENT mydb = ManageDB(collection) temp_doc = self.__dict__ result = mydb.insert_json(temp_doc) except Exception as error: logger.info("creating document "+ str(error)) finally: if mydb is not None: mydb.close() return result
def find_by_attr(self, key, value): '''finds a user object by the attribute id''' result = [] mydb = None try: collection = LINK mydb = ManageDB(collection) docs = mydb.select(key, value) if len(docs) > 0: result = docs return result else: logger.info("documents not found on bd") except Exception as e: logger.info("finding link" + str(e)) finally: if mydb is not None: mydb.close() return result
def update(self): '''updates a link on the bd''' result = False mydb = None if self.doc_id is None: return False try: collection = LINK mydb = ManageDB(collection) temp_link = self.__dict__ link_id = temp_link.pop("link") temp_link.pop("_id") result = mydb.update({"link": link_id}, temp_link) except Exception as error: logger.info("updating link" + str(error)) result = False finally: if mydb is not None: mydb.close() return result
def update(self): '''updates a user on the bd''' result = None mydb = None if self.doc_id is None: return None try: collection = DOCUMENT mydb = ManageDB(collection) temp_doc = self.__dict__ doc_id = temp_doc.pop("doc_id") temp_doc.pop("_id") result = mydb.update({"doc_id": doc_id}, temp_doc) except Exception as error: logger.info("updating document"+ str(error)) result = None finally: if mydb is not None: mydb.close() return result
def create(self): '''creates a new user on the bd''' result = False mydb = None try: collection = "SignerUser" mydb = ManageDB(collection) if not self.find_by_attr("email", self.email): self.create_keys() mydb.insert_json(self.__dict__) result = self else: logger.info("signer user already created") result = self.find_by_attr("email", self.email) except Exception as error: logger.info("creating user", error) finally: if mydb is not None: mydb.close() return result