def _handle_NewAccount(self, event): accounts = self._load() accounts.append(event.account) if self._has_duplicate_keys(accounts): return persistance.write(self._path, accounts) kernel.queue(events.Success("Account created"))
def _handle_DeleteAccount(self, event): accounts = self._load() a = self._find_by_key(accounts, event.key) if a == None: kernel.queue(events.NotFound()) return accounts.remove(a) persistance.write(self._path, accounts) kernel.queue(events.Success("Account removed"))
def _handle_UpdateAccountField(self, event): accounts = self._load() a = self._find_by_key(accounts, event.key) if a == None: kernel.queue(events.NotFound()) return if event.field == "password": a.setEncryptionKey(event.encryption_key) a.setPassword(event.value) else: setter = "set%s" % (event.field.title()) if hasattr(a, setter): method = getattr(a, setter) method(event.value) if self._has_duplicate_keys(accounts): return persistance.write(self._path, accounts) kernel.queue(events.Success("Account updated"))
def backup_state(): import persistance result = persistance.write(engine) return jsonify(result), 200