def create_account(self, username, password, role, name, surname, email): """Create a new account.""" if username in self.accounts: raise ValueError("%s already registered" % username) if role not in [ROLE_ADMIN, ROLE_USER]: raise ValueError("Invalid role %s" % role) session = Session() account = TblAccount(username=username, password=password, role=role, name=name, surname=surname, email=email) session.add(account) session.commit() self.accounts[account.username] = Account(account.username, account.password, account.name, account.surname, account.email, account.role)
def __load_accounts(self): """Load accounts table.""" for account in Session().query(TblAccount).all(): self.accounts[account.username] = Account( account.username, account.password, account.name, account.surname, account.email, account.role)
def create_account(self, username, password, role, name, surname, email): """Create a new account.""" if username in self.accounts: LOG.error("'%s' already registered", username) raise ValueError("%s already registered" % username) session = Session() account = TblAccount(username=username, password=password, role=role, name=name, surname=surname, email=email) session.add(account) session.commit() self.accounts[account.username] = Account(account.username, account.password, account.name, account.surname, account.email, account.role)