def pay_account(self, accountName, amount): auth.check_login(response = True) DB = db.DBConnection() sqlResult = DB.select("SELECT accCredit FROM accounts WHERE accName = ?", [accountName]) currentCredit = sqlResult[0]['accCredit'] currentCredit = currentCredit + Decimal(amount) DB.action("UPDATE accounts SET accCredit = ? WHERE accName = ?", [currentCredit, accountName]) return {"result": "OK", "newCredit": str(currentCredit)}
def new_account(self, accountName): auth.check_login(response = True) DB = db.DBConnection() checkExistingAccount = DB.select("SELECT accName FROM accounts WHERE accName = ?", [accountName]) if checkExistingAccount != []: return {"result": "NOT OK", "message": "Deze naam wordt al gebruikt!"} else: DB.action("INSERT INTO accounts (accName, accCredit, accTotalSpend) VALUES (?, ?, ?)", [accountName, Decimal('0.00'), Decimal('0.00')]) return {"result": "OK"}
def change_password(self, oldPassword = None, newPassword = None): adminName = auth.check_login(response = True) if oldPassword != None and newPassword != None: success = auth.change_password(adminName, oldPassword, newPassword) if success: raise cherrypy.HTTPRedirect("/accounts") else: message = "Het huidige wachtwoord klopt niet" return renderTemplate("settings.html", message = message) else: return renderTemplate("settings.html")
def accounts(self): auth.check_login() DB = db.DBConnection() accounts = DB.select("SELECT accName, accCredit, accTotalSpend FROM accounts") return renderTemplate(templateName = "accounts.html", accounts = accounts)
def del_account(self, accountName): auth.check_login(response = True) DB = db.DBConnection() DB.action("DELETE FROM accounts WHERE accName = ?", [accountName]) return {"result": "OK"}