Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)