Пример #1
0
def user_factory(handler, registry):
    global ANONYMOUS_USER
    if ANONYMOUS_USER is None:
        login = registry.settings.get("auth.anonymous_user")
        try:
            ANONYMOUS_USER = db.query(User).filter(User.login == login).one()
        except NoResultFound:
            log.error(
                "Misconfigured anonymous user '{}'. User not found.".format(
                    login))
            sys.exit(1)

    def user_tween(request):
        if static_urls.match(request.path):
            return handler(request)
        # Cache must be existing. Because we are in a tween this code
        # is executed _before_ the "NewRequest" event is handled in the
        # application which usually ensures that the cache is
        # initialised. So we will "pre"-init the cache here.
        init_cache(request)
        if not request.user:
            # Do not (re)-authorize the user on logout and autologout
            # pages.
            if request.path not in [
                    request.route_path("autologout"),
                    request.route_path("logout")
            ]:
                request.user = ANONYMOUS_USER
                request.session["auth.anonymous_user"] = ANONYMOUS_USER.login
                request.session.save()
                headers = remember(request, ANONYMOUS_USER.id)
                return HTTPFound(location=request.path, headers=headers)
        return handler(request)

    return user_tween
Пример #2
0
def user_factory(handler, registry):
    global ANONYMOUS_USER
    if ANONYMOUS_USER is None:
        login = registry.settings.get("auth.anonymous_user")
        ANONYMOUS_USER = db.query(User).filter(User.login == login).one()

    def user_tween(request):
        if not request.user:
            log.info("Anonymous login")
            request.user = ANONYMOUS_USER
            request.session["auth.anonymous_user"] = ANONYMOUS_USER.login
            request.session.save()
            target_url = request.route_path("home")
            headers = remember(request, ANONYMOUS_USER.id)
            return HTTPFound(location=target_url, headers=headers)
        return handler(request)

    return user_tween
Пример #3
0
def setup_modules(config):
    """Will iterate over all configured modules in the application.
    Configured modules are loaded from database. For each module it will
    call the setup_modul method."""
    for modul in NTDBSession.query(ModulItem).all():
        setup_modul(config, modul)
Пример #4
0
def setup_modules(config):
    """Will iterate over all configured modules in the application.
    Configured modules are loaded from database. For each module it will
    call the setup_modul method."""
    for modul in NTDBSession.query(ModulItem).all():
        setup_modul(config, modul)