Esempio n. 1
0
def includeme(config, debug=False):
    settings = config.registry.settings
    if len([k.startswith('sqlalchemy.') for k in settings]):
        engine = engine_from_config(settings, 'sqlalchemy.')
        initialize_sql(engine)
    # verify captcha settings
    captcha = get_registry_key('auth.use_captcha', False)
    if captcha:
        settings['apex.use_recaptcha_on_login'] = False
        settings['apex.use_recaptcha_on_forgot'] = False
        settings['apex.use_recaptcha_on_register'] = True
        settings['apex.use_recaptcha_on_reset'] = False
        settings['apex.use_recaptcha_on_useradd'] = False
        rpubk = get_registry_key('auth.recaptcha_public_key', '')
        rprivk =  get_registry_key('auth.recaptcha_private_key', '')
        if rpubk:
            settings['apex.recaptcha_public_key'] = rpubk
        if rprivk:
            settings['apex.recaptcha_private_key'] = rprivk



    projects_dir = settings.get('mobyle2.projects_dir')
    if not projects_dir: raise Exception('please configure mobyle2.projects_dir')
    if not os.path.exists(projects_dir):
        try:
            os.makedirs(projects_dir)
            os.chmod(projects_dir, 0600)
        except Exception, e:
            raise Exception('Cant create directory: %s' % projects_dir)
Esempio n. 2
0
def register_default_acls(session, force=False):
    # authentication settings
    if not force:
        force = not get_registry_key('mobyle2.configured_acl', False)
    if not force:
        return
    for p in default_acls:
        try:
            perm = Permission.by_name(p)
        except:
            import pdb;pdb.set_trace()  ## Breakpoint ##

        roles = default_acls[p]
        for role in roles:
            access = roles[role]
            orole = Role.by_name(role)
            if access:
                if not perm in orole.global_permissions:
                    orole.global_permissions.append(perm)
                    session.add(orole)
                    session.commit()
            else:
                if perm in orole.global_permissions:
                    del orole.global_permissions[orole.global_permissions.index(perm)]
                    session.add(orole)
                    session.commit()
            set_registry_key('mobyle2.configured_acl', "1")
    session.flush()
Esempio n. 3
0
def register_default_roles(session, force=False):
    # authentication settings
    if not force:
        force = not get_registry_key('mobyle2.configured_roles', False)
    if not force:
        return
    for k in default_roles:
        try:
            session.query(Role).filter(Role.name == k).one()
        except NoResultFound, e:
            try:
                session.add(
                    Role(name=k, description=default_roles[k])
                )
                session.commit()
            except IntegrityError:
                session.rollback()
Esempio n. 4
0
 def get_base_params(self):
     params = {'view': self}
     params.update(get_base_params(self))
     params['need_restart'] = get_registry_key('mobyle2.needrestart')
     return params
Esempio n. 5
0
def self_registration():
    return get_registry_key('auth.self_registration')
Esempio n. 6
0
def projects_dir(directory=None):
    if directory is not None:
        set_registry_key(PROJECTS_DIR, directory)
    return get_registry_key(PROJECTS_DIR)