Force Login Module for Magento 2
Clone or download
Latest commit 93f3df0 Aug 1, 2018
Permalink
Failed to load latest commit information.
.github Add Github issue template Aug 1, 2018
Api Apply fixes sugested by the EQP tool Dec 19, 2017
Block/Adminhtml Apply fixes sugested by the EQP tool Dec 19, 2017
Controller Fixes issue #117 with multiple stores and domains having store name i… Jul 1, 2018
Helper/Strategy Apply fixes sugested by the EQP tool Dec 19, 2017
Model Apply fixes sugested by the EQP tool Dec 19, 2017
Plugin Fix scrutinizer findings Dec 27, 2017
Repository Apply fixes sugested by the EQP tool Dec 19, 2017
Setup Fixes #118 Jun 10, 2018
Test/Unit Fixes issue #117 with multiple stores and domains having store name i… Jul 1, 2018
Ui/Component/Listing/Column Apply fixes sugested by the EQP tool Dec 19, 2017
Validator Apply fixes sugested by the EQP tool Dec 19, 2017
docs Update docs to fix typos and reflect latest changes Dec 25, 2017
env #91 Fixed syntax issue in layout xml, invalid block definition Oct 26, 2017
etc Fixes #118 Jun 10, 2018
resources #73 Updated documentation Jul 11, 2017
view/adminhtml Rename button "delete" Dec 25, 2017
.coveralls.yml Add coveralls.io support in Travis build Dec 27, 2017
.gitignore Fixes #118 Jun 10, 2018
.travis.yml Add mising check if composer auth.json can be decrypted in Travis build Dec 27, 2017
CONTRIBUTING.md Add contributing guide Feb 18, 2017
Changelog.md Changelog update Dec 25, 2017
LICENSE Initial commit Mar 13, 2016
README.md Fix typo in README Feb 13, 2018
auth.json.enc Store Composer auth info in encrypted file Mar 19, 2017
build.sh Cleanup Oct 31, 2017
build.xml Add Magento EQP tool in Travis build Jan 1, 2018
composer.json Fixes #118 Jun 10, 2018
composer.lock update composer.lock Jun 10, 2018
docker-compose.yml Convert "bitExpert" namespace to "BitExpert" to fix the Magento 2.2 X… Dec 9, 2017
mr2 Added magento2 docker environment Jun 12, 2017
phpunit.xml Increase test coverage Oct 25, 2017
registration.php Convert "bitExpert" namespace to "BitExpert" to fix the Magento 2.2 X… Dec 9, 2017
validate_m2_package.php Added build script Aug 8, 2017

README.md

Force Login Module for Magento® 2

Build Status Coverage Status

The Force Login Module for Magento® 2 allows you to restrict which pages a visitor is able to see. Visitors get redirected to the login page if the page is not marked visitable. The Force Login Module for Magento® 2 is especially useful for merchants serving only a specific group of users, e.g. enterprise related business partners and need to ensure that only those users are able to browse the the website or the product catalog.

Features:

  • Force your guest visitors to log in first (or register), before allowing them to visit your pages and catalog
  • Administration: Manage the whitelist rules by the GUI in the administration area
  • ACL: Restrict the administration of whitelist rules to certain backend user groups
  • Whitelisting: Define url rules as pattern to define which pages guest visitors can visit without logging in first
  • Multistore-Support: Define if whitelist rules either apply globally or for specific stores

Installation

The preferred way of installing bitexpert/magento2-force-customer-login is through Composer. Simply add bitexpert/magento2-force-customer-login as a dependency:

composer.phar require bitexpert/magento2-force-customer-login

Optional you can download the latest version here and install the decompressed code in your projects directory under app/code/BitExpert/ForceCustomerLogin.

Post-Install

After the installment of the module source code, the module has to be enabled by the Magento® 2 CLI.

bin/magento module:enable BitExpert_ForceCustomerLogin

System Upgrade

After enabling the module, the Magento® 2 system must be upgraded.

If the system mode is set to production, run the compile command first. This is not necessary for the developer mode.

bin/magento setup:di:compile

To upgrade the system, the upgrade command must be run.

bin/magento setup:upgrade

Clear Cache

At last, the Magento® 2 should be cleared by running the flush command.

bin/magento cache:flush

Sometimes, other cache systems or services must be restarted first, e.g. Apache Webserver and PHP FPM.

User Guide

Find the complete user guide here.

How to use

The usage of the Force Login Module for Magento® 2 is applied implicitly by redirecting visitors if the called URI does not match any configured whitelisted url rules.

Whitelisting

Whitelisting is based upon the usage of rules. The strategy selection defines how the rules are interpreted, details are listed below. By default, some static rules are already listed. The following example shows, how to add a whitelist entry for the homepage (startpage).

Navigate to the Overview Grid and use the Add Entry button.

  • Enter Homepage into the text field beside from the Label label.
  • Enter ^/?$ into the text field beside from the Url Rule label.
  • Select All Stores from the selection field beside from the Store label.

Use the Save button in the upper menu. After being redirected to the Overview Grid, the new entry should appear to the list and the systems homepage should be available for guest visitors.

How to configure

Administration

The Force Login Module for Magento® 2 allows you to enable or disable the module itself on the level of websites, stores and store views.

If the module is disabled, the whitelist ruling and the redirection are not applied. If the module is enabled based upon the configuration, the whitelist rules are process, which themselves are also configurable for all enabled stores or just specific ones.

After installing and enabling Force Login Module for Magento® 2 with the CLI, you must be able to navigate to Stores > Configuration > Force Login, where you are able to configure the availability of the module for each website, store and store view.

In the administration configuration, you are also able to setup the URL the redirecting is targeting to if not whitelist rule is matching.

alt text

Navigation

Navigating through the Magento® 2 backend menu by clicking onto Customers you must see a new menu entry Forced Login Whitelist.

Enter this menu entry.

alt text

Overview Grid

You can add new entries by clicking on the Add Entry button in the upper right corner ( 1 ), see below. The grid ( 2 ) contains all existing whitelisted Url Rules, for which the forced redirect to the Customer Login Page is omitted. The Url Rules ( 3 ) are part of a regular expression checking on the called Url and tries to match against the whitelist. Url Rules may be related to all stores or to a specific one ( 4 ). All rules except some mandatory ones are editable ( 5 ) and removeable ( 6 ).

alt text

Detail Form

You can return to the Overview Grid by using the Back button ( 1 ). The Label value has only declarative character and is for information purpose only ( 2 ). The Url Rule is an expression checking on the called Url and tries to match against the whitelist ( 3 ). Url Rules may be related to all stores or to a specific one ( 4 ). The strategy selection ( 5 ) defines how the Url Rule is interpreted, details are listed below. Persist the rule by using the Save button ( 6 ).

alt text

Strategies

Static

Rule is used as a literal value and will be added onto the base url for matching. This is default behaviour.

RegEx-All

Rule is based on regular expression, and will be used for looking up matching anywhere in the current Url.

Tests

You can run the unit tests with the following command (requires dependency installation):

composer test

Contribution

Feel free to contribute to this module by reporting issues or create some pull requests for improvements.

License

The Force Login Module for Magento® 2 is released under the Apache 2.0 license.