Beispiel #1
0
def create_session(username, password):
    """
    Create a session for the user, and then return the key.
    """
    user = User.get_user_by_password(username, password)
    if not user:
        raise InvalidInput('Username or password incorrect')
    session_key = random_string(15)
    while config.auth_session.get(session_key):
        session_key = random_string(15)
    config.auth_session.set(session_key, user.username, config.auth_session_expire)
    return {'session_key': session_key, 'user': user}
Beispiel #2
0
def create_session(username, password):
    """
    Create a session for the user, and then return the key.
    """
    user = User.objects.get_user_by_password(username, password)
    auth_session_engine = get_config('auth_session_engine')
    if not user:
        raise InvalidInput('Username or password incorrect')
    session_key = random_string(15)
    while auth_session_engine.get(session_key):
        session_key = random_string(15)
    auth_session_engine.set(session_key, user.username, get_config('auth_session_expire'))
    return {'session_key': session_key, 'user': user}
Beispiel #3
0
def create_session(username, password):
    """
    Create a session for the user, and then return the key.
    """
    user = User.objects.get_user_by_password(username, password)
    auth_session_engine = get_config('auth_session_engine')
    if not user:
        raise InvalidInput('Username or password incorrect')
    session_key = random_string(15)
    while auth_session_engine.get(session_key):
        session_key = random_string(15)
    auth_session_engine.set(session_key, user.username,
                            get_config('auth_session_expire'))
    return {'session_key': session_key, 'user': user}
Beispiel #4
0
def get_bucket_name(username, domain, aws_key, aws_secret):
    """
    Create a bucket for the usage of LibraryDSS.
    Returned is the name of that bucket.
    """
    conn = S3Connection(aws_key, aws_secret)
    try:
        bucket = conn.create_bucket("lib_%s_%s" % (username, domain))
    except:
        bucket = conn.create_bucket("lib_%s_%s_%s" % (username, domain, random_string(3)))

    return bucket.name
Beispiel #5
0
def initialize(module_name=None):
    """
    Build the giotto settings object. This function gets called
    at the very begining of every request cycle.
    """
    import giotto
    from giotto.utils import random_string, switchout_keyvalue
    from django.conf import settings

    setattr(giotto, '_config', GiottoSettings())

    if not module_name:
        # For testing. No settings will be set.
        return

    project_module = importlib.import_module(module_name)
    project_path = os.path.dirname(project_module.__file__)
    setattr(giotto._config, 'project_path', project_path)

    try:
        secrets = importlib.import_module("%s.controllers.secrets" %
                                          module_name)
    except ImportError:
        secrets = None

    try:
        machine = importlib.import_module("%s.controllers.machine" %
                                          module_name)
    except ImportError:
        machine = None

    config = importlib.import_module("%s.controllers.config" % module_name)

    if config:
        for item in dir(config):
            setting_value = getattr(config, item)
            setattr(giotto._config, item, setting_value)

    if secrets:
        for item in dir(secrets):
            setting_value = getattr(secrets, item)
            setattr(giotto._config, item, setting_value)
    else:
        logging.warning("No secrets.py found")

    if machine:
        for item in dir(machine):
            setting_value = getattr(machine, item)
            setattr(giotto._config, item, setting_value)
    else:
        logging.warning("No machine.py found")

    settings.configure(SECRET_KEY=random_string(32),
                       DATABASES=get_config('DATABASES'),
                       INSTALLED_APPS=(module_name, 'giotto'))

    ss = get_config('session_store', None)
    if ss:
        class_ = switchout_keyvalue(ss)
        setattr(giotto._config, "session_store", class_())

    cache_engine = get_config("cache", None)
    if hasattr(cache_engine, 'lower'):
        # session engine was passed in as string, exchange for engine object.
        class_ = switchout_keyvalue(cache_engine)
        e = class_(host=get_config("cache_host", "localhost"))
        setattr(giotto._config, "cache_engine", e)
Beispiel #6
0
def initialize(module_name=None):
    """
    Build the giotto settings object. This function gets called
    at the very begining of every request cycle.
    """
    import giotto
    from giotto.utils import random_string, switchout_keyvalue
    from django.conf import settings

    setattr(giotto, '_config', GiottoSettings())

    if not module_name:
        # For testing. No settings will be set.
        return

    project_module = importlib.import_module(module_name)
    project_path = os.path.dirname(project_module.__file__)
    setattr(giotto._config, 'project_path', project_path)

    try:
        secrets = importlib.import_module("%s.controllers.secrets" % module_name)
    except ImportError:
        secrets = None

    try:
        machine = importlib.import_module("%s.controllers.machine" % module_name)
    except ImportError:
        machine = None

    config = importlib.import_module("%s.controllers.config" % module_name)

    if config:
        for item in dir(config):
            setting_value = getattr(config, item)
            setattr(giotto._config, item, setting_value)

    if secrets:
        for item in dir(secrets):
            setting_value = getattr(secrets, item)
            setattr(giotto._config, item, setting_value)
    else:
        logging.warning("No secrets.py found")

    if machine:
        for item in dir(machine):
            setting_value = getattr(machine, item)
            setattr(giotto._config, item, setting_value)
    else:
        logging.warning("No machine.py found")

    settings.configure(
        SECRET_KEY=random_string(32),
        DATABASES=get_config('DATABASES'),
        INSTALLED_APPS=(module_name, 'giotto')
    )

    ss = get_config('session_store', None)
    if ss:
        class_ = switchout_keyvalue(ss)
        setattr(giotto._config, "session_store", class_())

    cache_engine = get_config("cache", None)
    if hasattr(cache_engine, 'lower'):
        # session engine was passed in as string, exchange for engine object.
        class_ = switchout_keyvalue(cache_engine)
        e = class_(host=get_config("cache_host", "localhost"))
        setattr(giotto._config, "cache_engine", e)