• Stars
    star
    166
  • Rank 227,093 (Top 5 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Force Customer Login Module for Magento 2

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
  • Hyvä Themes compatible

Requirements:

  • PHP 7.4 or PHP 8.1
  • Magento 2.4.0 or higher

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.

Composer error package bitexpert/magento2-force-customer-login exists

When you have errors after installing trough composer there is probably an issue with version numbers between Packagist and Magento repo. You can update your project composer file to fix this:

{
  "repositories": [
    {
      "type": "composer",
      "url": "https://repo.magento.com/",
      "canonical": false
    }
  ]
}

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.

RegEx-All Negation

Based on the RegEx-All strategy, but negates the result. Helpful if only a few pages should be restricted.

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.

More Repositories

1

disco

PSR-11 compatible Dependency Injection Container for PHP.
PHP
139
star
2

phpstan-magento

Magento specific extension for PHPStan
PHP
133
star
3

adrenaline

[DEPRECATED] A PSR-7 micro framework built on top of the Adroit middleware to speed up your development ;)
PHP
31
star
4

adroit

[DEPRECATED] ADR/PSR-7 middleware
PHP
27
star
5

magerun2-list-api-endpoints

Plugin for netz98 Magerun2 to list all API endpoints
PHP
16
star
6

phing-securitychecker

[DEPRECATED] Security Checker Phing Task
PHP
15
star
7

eclipse-smartsprites

[DEPRECATED] Eclipse Plugin offering Smartsprites integration
Java
11
star
8

etcetera

Extract Transform Library
PHP
9
star
9

ng2-combobox

[DEPRECATED] The only true Angular Combobox component ;)
TypeScript
9
star
10

magerun2-password-normalizer

n98-Magerun2 Plugin for normalizing all customer-email-addresses and passwords
PHP
9
star
11

eclipse-vagrant

[DEPRECATED] Eclipse Vagrant Plugin
Java
9
star
12

captainhook-infection

Captain Hook Plugin to run InfectionPHP only against the changed files of a commit
PHP
9
star
13

composer-phive-bridge

PHP
7
star
14

liquibase-phing

[DEPRECATED] Phing tasks to interact with Liquibase for database change management
PHP
7
star
15

prophiler-psr7-middleware

[DEPRECATED] Prophiler PSR7 Middleware
PHP
7
star
16

captainhook-validateauthor

Captain Hook Plugin to check if commit author is valid (e.g. email in whitelist)
PHP
7
star
17

addItEasy

[DEPRECATED] addItEasy - a PSR-7 compatible flat file CMS
PHP
7
star
18

slf4psrlog

Simple Logging Facade for Loggers implementing PSR-3 logging interface.
PHP
6
star
19

html5-offline-demo

[DEPRECATED] HTML5 Offline Todolist Demo
JavaScript
5
star
20

composer-authstore-plugin

[DEPRECATED] Composer Authstore plugin
PHP
5
star
21

mntyjs

[DEPRECATED] Lightweight plugin system based on require.js, jQuery and Base.js.
JavaScript
5
star
22

pathfinder

[DEPRECATED] A PSR-7 based router
PHP
5
star
23

ssbjs

Simple Service Bus for Javascript
TypeScript
5
star
24

disco-demos

Demo applications to showcase how to use Disco.
4
star
25

captainhook-rejectpush

Captain Hook Plugin to reject a remote push when certain commit Ids are found in history
PHP
4
star
26

grunt-mntyjs

[DEPRECATED] Grunt task for mnty.js
JavaScript
4
star
27

sulu-securitytxt-bundle

Sulu Bundle to manage security.txt files
PHP
4
star
28

eclipse-yuicompressor

[DEPRECATED] Eclipse YUICompressor Plugin
Java
4
star
29

eclipse-composer

[DEPRECATED] Eclipse Plugin offering Composer integration
4
star
30

cs-jshint

[DEPRECATED] bitExpert jshint configuration
3
star
31

just-run-phing

[DEPRECATED] Allow developers to "just run phing."
3
star
32

typo3-basicauth

TYPO3 Basic Auth extension
PHP
3
star
33

sylius-force-login

Force Customer Login Plugin for Sylius
PHP
3
star
34

cs-scsslint

[DEPRECATED] bitExpert scsslint style configuration
2
star
35

silex-twig-translation

[DEPRECATED] Silex / Twig extension to deal with Symfony/Translation in templates.
PHP
2
star
36

mattermost-client-node

[DEPRECATED] Mattermost client for node js
TypeScript
2
star
37

eclipse-svn-export

[DEPRECATED] Eclipse Plugin to export files based on their svn revisions
Java
2
star
38

specialist

[DEPRECATED] A simple array container implementing container-interop. Array all the things!
PHP
2
star
39

etcetera-demo

etcetera demo project
PHP
1
star
40

psql-nosql-workshop-dwx16

Developer Week 2016 PostgreSQL / NoSQL Dev Session
1
star
41

testiat-api-client-node

[DEPRECATED]
JavaScript
1
star
42

testiat-api-client-php

[DEPRECATED]
PHP
1
star
43

profitbricks-php-cli

[DEPRECATED] PHP CLI Client to interact with the profitbricks API
PHP
1
star
44

cs-jscs

[DEPRECATED] bitExpert jscs configuration
JavaScript
1
star
45

profitbricks-php-sdk

[DEPRECATED] PHP SDK for the profitbricks API
PHP
1
star
46

composer-webasset-installer

[DEPRECATED] Composer Webasset Installer
PHP
1
star
47

oauth2-server-storage-dbal

[DEPRECATED] Dbal storage implementation for OAuth 2.0 Server
PHP
1
star
48

ngx-radial-progress

[DEPRECATED]
TypeScript
1
star