cancel
Showing results for 
Search instead for 
Did you mean: 

Password Protect front end

Password Protect front end

I'm wondering if anyone is aware of a method to password protect a magento store. 

 

We require users to login before they have access to our site. At the moment we are using htpasswd, however this is causing issues some users, and is not a method we can continue to use.

 

I've searched for addons, but there doesn't seem to be anything out there.

1 REPLY

Re: Password Protect front end

Hi @CaptainG,

 

I've checked the Marketplace and I've found, in theory, a solution: https://marketplace.magento.com/catalogsearch/result/?q=login#q=login&idx=m2_cloud_prod_default_prod...

 

If not is a simple customization. You can observe the predispatch event and redirect to login if customer is guest.

 

Let's say you have a module called Vendor_Wholesalers. Your config.xml file will have something like:

 

<?xml version="1.0"?>
<config>
    <modules>
        <Vendor_Wholesalers>
            <version>0.1.0</version>
        </Vendor_Wholesalers>
    </modules>
    <frontend>
        <events>
            <controller_action_predispatch>
                <observers>
                    <wholesalers_site>
                        <class>wholesalers/observer</class>
                        <method>redirectPage</method>
                    </wholesalers_site>
                </observers>
            </controller_action_predispatch>
        </events>
    </frontend>
    <global>
        <models>
            <wholesalers>
                <class>Vendor_Wholesalers_Model</class>
            </wholesalers>
        </models>
    </global>
</config>

Then, the observer will use something like:

 

class Vendor_Wholesalers_Model_Observer {

    public function redirectPage($event)
    {
        $action = $event->getEvent();
        $requestString  = $action->getControllerAction()->getRequest()->getRequestString();
        if (!$this->_getSession()->isLoggedIn()) {
            if ($requestString !== '/customer/account/login/' && $requestString !== '/customer/account/loginPost/'  && $requestString !== '/customer/account/logout/') {
                header('Location:' . Mage::getUrl('customer/account/login/'));
                exit;
            }
        }
    }

    private function _getSession()
{ return Mage::getSingleton('customer/session'); } }

I know isn't perfect and isn't the whole example but it could be something similar.

 

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"