Ejemplo n.º 1
0
    def create_user(self, admin_token, tenant_id, user):
        self.__validate_token(admin_token)

        dtenant = db_api.tenant_get(tenant_id)
        if dtenant == None:
            raise fault.UnauthorizedFault("Unauthorized")
        if not dtenant.enabled:
            raise fault.TenantDisabledFault("Your account has been disabled")

        if not isinstance(user, users.User):
            raise fault.BadRequestFault("Expecting a User")

        if user.user_id == None:
            raise fault.BadRequestFault("Expecting a unique User Id")

        if db_api.user_get(user.user_id) != None:
            raise fault.UserConflictFault(
                "An user with that id already exists")

        if db_api.user_get_email(user.email) != None:
            raise fault.EmailConflictFault(
                "Email already exists")

        duser = db_models.User()
        duser.id = user.user_id
        duser.password = user.password
        duser.email = user.email
        duser.enabled = user.enabled
        duser.tenant_id = tenant_id
        db_api.user_create(duser)
        

        return user
Ejemplo n.º 2
0
def main():
    usage = "usage: %prog username password"
    parser = optparse.OptionParser(usage)
    options, args = parser.parse_args()
    if len(args) != 2:
        parser.error("Incorrect number of arguments")
    else:
        username = args[0]
        password = args[1]
        try:
            u = models.User()
            u.id = username
            u.email = username
            u.password = password
            u.enabled = True
            db_api.user_create(u)
            print 'User', u.id, 'created.'
        except Exception, e:
            print 'Error creating user', username, ':', str(e)
Ejemplo n.º 3
0
    def fixture_create_user(self, **kwargs):
        """
        Creates a user fixture. If the user's tenant ID is set, and the tenant
        does not exist in the database, the tenant is created.

        :params **kwargs: Attributes of the user to create
        """
        values = kwargs.copy()
        tenant_id = values.get('tenant_id')
        if tenant_id:
            if not db_api.tenant_get(tenant_id):
                db_api.tenant_create({'id': tenant_id,
                                      'enabled': True,
                                      'desc': tenant_id})
        user = db_api.user_create(values)
        logger.debug("Created user fixture %s", values['id'])
        return user