コード例 #1
0
def generate_default_accounts():
    """Generate default accounts.

    Three default accounts (one root account and two user accounts are created
    the first time the controller is started.
    """

    if not Session().query(TblAccount).all():

        LOG.info("Generating default accounts")

        session = Session()
        session.add(
            TblAccount(username="******",
                       password="******",
                       role="admin",
                       name="Administrator",
                       surname="",
                       email="*****@*****.**"))
        session.add(
            TblAccount(username="******",
                       password="******",
                       role="user",
                       name="Foo",
                       surname="",
                       email="*****@*****.**"))
        session.add(
            TblAccount(username="******",
                       password="******",
                       role="user",
                       name="Bar",
                       surname="",
                       email="*****@*****.**"))
        session.commit()
コード例 #2
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)
コード例 #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)