Skip to content

Latest commit

 

History

History
118 lines (87 loc) · 3.24 KB

File metadata and controls

118 lines (87 loc) · 3.24 KB

Novactive eZ Protected Content Bundle

A bundle that provides quick password protection on Contents.

How it works

Allows you to add 1 on N password on a Content in the Admin UI. Once a protection is set, the Content becomes Protected. In this situation you can have 3 new variables in the view full

  • canReadProtectedContent (always)
  • requestProtectedContentPasswordForm (if content is protected by password)
  • requestProtectedContentEmailForm (if content is protected with email verification)

Allowing you do:

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

You can also manage this globally through the pagelayout wrapping the content block.

Once you have unlocked the content, canReadProtectedContent will be true

HTTP Cache is disabled for Protected Content.

Installation

Requirements

  • eZ Platform 2+
  • PHP 7.1+
  • MySQL 5.7.8+ / Maria DB 10.1+

Installation steps

Run composer require novactive/ezprotectedcontentbundle to install the bundle and its dependencies:

Register the bundles

Activate the bundle in app\AppKernel.php file.

// app\AppKernel.php

public function registerBundles()
{
   ...
   $bundles = array(
        new FrameworkBundle(),
        ...
        // Novactive eZ Protected Content Bundle
        new Novactive\Bundle\eZProtectedContentBundle\NovaeZProtectedContentBundle()
   );
   ...
}

Add routes

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

Install the database schema

bin/console novaezprotectedcontent:install

Varnish

This module add a cookie to unlock the contents that match it, for that reason you want to keep all the cookie that starts with PasswordProvided::COOKIE_PREFIX (i.e: 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, "^[; ]+|[; ]+$", "");
    }

Contributing

Contributing

Change and License

License


Made with <3 by novactive.