Ejemplo n.º 1
0
def create_user(uname, db):
    """Helper function to create some system users we need in VH.

    uname will be owned by the system group andit will have been created by
    the system account.
    """

    account = Account(db)
    constants = Factory.get("Constants")()
    try:
        account.find_by_name(uname)
        logger.debug("Found account with name=%s, id=%s", account.account_name,
                     account.entity_id)
        return
    except Errors.NotFoundError:
        sys_group = get_system_group(db)
        sys_account = get_system_account(db)
        account.populate(
            uname,
            constants.entity_group,  # owned by 
            sys_group.entity_id,  # ... system group
            constants.account_program,
            sys_account.entity_id,  # created by system account
            None)  # no expire (duh!)
        account.write_db()
        logger.debug("Created account uname=%s, id=%s", account.account_name,
                     account.entity_id)
        logger.debug("Don't forget to set a password on uname=%s",
                     account.account_name)
Ejemplo n.º 2
0
def create_user(uname, db):
    """Helper function to create some system users we need in VH.

    uname will be owned by the system group andit will have been created by
    the system account.
    """

    account = Account(db)
    constants = Factory.get("Constants")()
    try:
        account.find_by_name(uname)
        logger.debug("Found account with name=%s, id=%s",
                     account.account_name, account.entity_id)
        return
    except Errors.NotFoundError:
        sys_group = get_system_group(db)
        sys_account = get_system_account(db)
        account.populate(uname,
                         constants.entity_group,       # owned by 
                         sys_group.entity_id,          # ... system group
                         constants.account_program, 
                         sys_account.entity_id, # created by system account
                         None)                  # no expire (duh!)
        account.write_db()
        logger.debug("Created account uname=%s, id=%s",
                     account.account_name, account.entity_id)
        logger.debug("Don't forget to set a password on uname=%s",
                     account.account_name)
Ejemplo n.º 3
0
    def populate(self, email, account_name, human_first_name, human_last_name, expire_date=None):
        """Populate data for a new VirtAccount.

        The caller is responsible for populating VirtAccount owner's human
        name elsewhere, if the name at all exists.
        
        @type email: basestring
        @param email:
          E-mail address associated with this VirtAccount. This is the only
          communication channel with whoever/whatever really owns a
          VirtAccount.

        @type account_name: basestring
        @param account_name:
          Account name for this VirtAccount structured as <name>@<realm>. The
          <realm> is fixed -- cereconf.VIRTACCOUNT_REALM. <name> cannot
          contain '@' and it cannot be empty. Account names are obviously
          unique (within the virthome realm). This can be used as an id. 

        @type expire_date: mx.DateTime.DateTime
        @param expire_date:
          Expiration date for the account (an expired account is no longer
          considered available for any external services). If nothing is
          specified a default of now (creation date) + 1 year is used.
        """

        # IVR 2009-04-11 FIXME: We need to check that at the very least the
        # email is in a valid format.
        assert email and email.strip(), "VirtHome e-mail addresses cannot be empty"

        # Double check that the username is available
        assert self.uname_is_available(account_name), "Username already taken"

        Account.populate(
            self,
            account_name,
            # VA is owned by the system
            self.const.entity_group,
            self.initial_group,
            self.account_type,
            # VA is created by the system
            self.initial_account,
            expire_date,
        )
        self.extend_expire_date(expire_date)

        self.populate_contact_info(self.const.system_virthome)
        self.populate_contact_info(self.const.system_virthome, self.const.virthome_contact_email, email)
        # Push the names in. NB! Don't store the full name -- we'll derive it
        # later as needed.
        self.populate_contact_info(self.const.system_virthome, self.const.human_first_name, human_first_name)
        self.populate_contact_info(self.const.system_virthome, self.const.human_last_name, human_last_name)
Ejemplo n.º 4
0
    def populate(self,
                 email,
                 account_name,
                 human_first_name,
                 human_last_name,
                 expire_date=None):
        """Populate data for a new VirtAccount.

        The caller is responsible for populating VirtAccount owner's human
        name elsewhere, if the name at all exists.
        
        @type email: basestring
        @param email:
          E-mail address associated with this VirtAccount. This is the only
          communication channel with whoever/whatever really owns a
          VirtAccount.

        @type account_name: basestring
        @param account_name:
          Account name for this VirtAccount structured as <name>@<realm>. The
          <realm> is fixed -- cereconf.VIRTACCOUNT_REALM. <name> cannot
          contain '@' and it cannot be empty. Account names are obviously
          unique (within the virthome realm). This can be used as an id. 

        @type expire_date: mx.DateTime.DateTime
        @param expire_date:
          Expiration date for the account (an expired account is no longer
          considered available for any external services). If nothing is
          specified a default of now (creation date) + 1 year is used.
        """

        # IVR 2009-04-11 FIXME: We need to check that at the very least the
        # email is in a valid format.
        assert email and email.strip(
        ), "VirtHome e-mail addresses cannot be empty"

        # Double check that the username is available
        assert self.uname_is_available(account_name), "Username already taken"

        Account.populate(
            self,
            account_name,
            # VA is owned by the system
            self.const.entity_group,
            self.initial_group,
            self.account_type,
            # VA is created by the system
            self.initial_account,
            expire_date)
        self.extend_expire_date(expire_date)

        self.populate_contact_info(self.const.system_virthome)
        self.populate_contact_info(self.const.system_virthome,
                                   self.const.virthome_contact_email, email)
        # Push the names in. NB! Don't store the full name -- we'll derive it
        # later as needed.
        self.populate_contact_info(self.const.system_virthome,
                                   self.const.human_first_name,
                                   human_first_name)
        self.populate_contact_info(self.const.system_virthome,
                                   self.const.human_last_name, human_last_name)