novactive/ezprotectedcontentbundle

Novactive eZ Protected Content Bundle 是一个 Ibexa 包,它提供了对内容的快速保护

v2.0.6 2023-12-08 13:33 UTC

README

这个存储库是我们所说的“子树拆分”:主存储库中的一个目录的只读副本。它由 Composer 用于允许开发人员依赖特定的包。

如果您想报告或贡献,您应该打开主存储库上的问题: https://github.com/Novactive/Nova-eZPlatform-Bundles

文档可通过此存储库中的 .md 文件获取,但还打包在此: https://novactive.github.io/Nova-eZPlatform-Bundles/master/ProtectedContentBundle/README.md.html

Downloads Latest version License

一个提供快速密码保护内容的包。

它是如何工作的?

允许您在管理界面中为内容添加一个密码。

一旦设置密码,内容将变为受保护状态。在这种情况下,您将在视图全中拥有两个新变量。这允许您

<h2>{{ ibexa_content_name(content) }}</h2>
{% if not canReadProtectedContent %}
    <p>This content has been protected by a password</p>
    <div class="protected-content-form">
        {{ form(requestProtectedContentPasswordForm) }}
    </div>
{% else %}
    {% for field in content.fieldsByLanguage(language|default(null)) %}
        <h3>{{ field.fieldDefIdentifier }}</h3>
        {{ ez_render_field(content, field.fieldDefIdentifier) }}
    {% endfor %}
{% endif %}

您还可以通过包装内容块的分页布局全局管理此内容。

一旦您解锁了内容,canReadProtectedContent 将为 true

受保护内容禁用 HTTP 缓存。

安装

安装步骤

将库添加到您的 composer.json 中,运行 composer require novactive/ezprotectedcontentbundle 来更新依赖关系。

然后在您的应用程序的 bundles.php 中注入该包。

    Novactive\Bundle\eZProtectedContentBundle\NovaeZProtectedContentBundle::class => [ 'all'=> true ],

添加路由

_novaezprotectedcontent_routes:
    resource: '@NovaeZProtectedContentBundle/Resources/config/routing/main.yml'

安装数据库模式

bin/console novaezprotectedcontent:install

Varnish

此模块为与它匹配的内容添加一个cookie来解锁,因此您希望保留所有以 PasswordProvided::COOKIE_PREFIX 开始的cookie(例如:protected-content-)。

 // Remove all cookies besides Session ID, as JS tracker cookies and so will make the responses effectively un-cached
    if (req.http.cookie) {
        set req.http.cookie = ";" + req.http.cookie;
        set req.http.cookie = regsuball(req.http.cookie, "; +", ";");
        set req.http.cookie = regsuball(req.http.cookie, ";[ ]*(eZSESSID[^=]*|protected-content-[^=]*)=", "; \1=");
        set req.http.cookie = regsuball(req.http.cookie, ";[^ ][^;]*", "");
        set req.http.cookie = regsuball(req.http.cookie, "^[; ]+|[; ]+$", "");
    }