def update_password(self, new_pass): """docstring for update_password""" enc_pass = encrypt_password(new_pass) c = self.db.cursor() str_query = ( """UPDATE %s AS vu JOIN %s as vd on vu.%s = vd.%s SET %s \ = """ % ( self.config["users"], self.config["domains"], self.config["users.domain_id"], self.config["domains.id"], self.config["users.password"], ) + """%s""" + """ WHERE %s = """ % self.config["users.user"] + """%s""" + """ AND %s = """ % self.config["domains.name"] + """%s""" ) c.execute(str_query, (enc_pass, self.user, self.domain)) if c.rowcount == 1: self.db.commit() self.password = enc_pass c.close() else: self.db.rollback() c.close() raise CouldNotQueryError(str_query % (new_pass, self.user, self.domain))
def create(self): enc_pass = encrypt_password(self.password) c = self.db.cursor() str_query = ( """INSERT INTO %s""" % self.config["users"] + """ (%s, %s, %s)""" % (self.config["users.domain_id"], self.config["users.user"], self.config["users.password"]) + " VALUES ((SELECT %s AS %s FROM %s WHERE %s=" % ( self.config["domains.id"], self.config["users.domain_id"], self.config["domains"], self.config["domains.name"], ) + "%s), %s, %s)" ) c.execute(str_query, (self.domain, self.user, enc_pass)) if c.rowcount == 1: self.db.commit() c.close() else: self.db.rollback() c.close() raise CouldNotQueryError(str_query % (self.domain, self.user, self.password))