-
The Previous Posting
« Magento Terms and Conditions Missing -
The Next Posting
The Correct Way To Set Up gzip with Magento »
Protect Magento Pages
We recently built a site with a wholesale area, utilizing the “Login Only Catalog Extension” and the “Customer Activation Extension”. While this did protect our wholesale inventory from prying eyes, it still left a few pages visible to the general public. Fortunately we found a fix that addressed this issue, and allowed us to secure the rest of the site, in a manor that was intuitive, and easy to implement.
Using Magento 1.3.2.4, the most recent version at this time, our setup is as follows. The credit for this fix goes to chillipepperdesign.
First create a page in app/design/frontend/default/your_theme/template/page/html/ called “auth_redirect.phtml” with the following content. In our case, our site has a wholesale sub-directory, edit as necessary.
1 2 3 4 5 6 7
< ?php Mage::getSingleton('customer/session')->setBeforeAuthUrl($this->getRequest()->getRequestUri()); //save requested URL for later redirection if(!Mage::getSingleton('customer/session')->isLoggedIn()) { // if not logged in header("Status: 301"); header('Location: http://www.sitename.com/wholesale/customer/account/login') ; // send to the login page exit; } ?>
Insert the following line in your app/design/frontend/default/your_theme/layout/page.xml file…
1
<block type="page/html" name="auth_redirect" as="auth_redirect" template="page/html/auth_redirect.phtml"/>
Directly after…
1
<block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml"></block>
Your template name may vary. Here’s how ours looked.
1 2 3 4 5
<default> <block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml"> <block type="page/html" name="auth_redirect" as="auth_redirect" template="page/html/auth_redirect.phtml"/> </block><block type="page/html_head" name="head" as="head"> </block></default>
Now you’ll want to edit your page templates. If your using a purchased theme, it may only have one or two page templates in it. Ie. 2columns-left.phtml, 2columns-right.phtml, and so on. In this case, we would suggest copying the missing templates from your default directory, to your theme directory. That way your sure these are the files being used in your site, and not the defaults.
At the top of each of these templates, add the following line directly after the php start tag, as such…
1 2 3 4
< ?php echo $this->getChildHtml('auth_redirect') /** * Magento *
Next we need to allow access to certain pages, to allow our wholesale customers to sign up for the site, recover a password, and access confirmation messages. In the file customer.xml, we need to add the following rule after each of the following. Your situation may be different, but the following are what you need if you want customers to be able to sign up themselves. Because we’re using the “Customer Activation Extension”, customers can sign up, but they must be approved by the admin before they can access the wholesale site.
The exceptions we included are as follows…
1 2 3 4 5
<customer_account_login> <remove name="auth_redirect" /> <!-- Mage_Customer --> <remove name="right"/> </customer_account_login>
…
1 2 3 4 5
<customer_account_forgotpassword> <remove name="auth_redirect" /> <remove name="right"/> <remove name="left"/> </customer_account_forgotpassword>
and…
1 2 3 4 5
<customer_account_confirmation> <remove name="auth_redirect" /> <remove name="right"/> <remove name="left"/> </customer_account_confirmation>
While most every page is now blocked on our wholesale site, we still want our customers to be able to access a few of our cms pages. Pages such as “contact us”, “legal terms”, or even the “home page”. All you have to do to enable these pages is add
1
<remove name="auth_redirect" />
to your “Layout Update XML”, under “Custom Design” in your cms pages.
This was by far one of the easier fixes I’ve seen, for what could seemingly be a major ordeal. I wish all our Magento experiences went this smoothly. While Magento is a powerful tool, with loads of features, it can at times be extremely temperamental, and downright finicky.
We hope this was helpful. If we left anything out, let us know. Happy computing.
As a Newbie, I am always searching online for articles that can help me. Thank you
I’m glad you found our musings useful. We truly enjoy our readers positive replies.
Best you should make changes to the blog subject Protect Magento Pages – CompRepairGurus to more catching for your blog post you write. I enjoyed the post withal.