Magento - Force User Login

Magento has a great approach to building multiple sites. It allows a webmaster to fill the database with source products and then present these in different ways to different groups either through one site or many different sites. This approach is perfect for large multinationals (for which I work!)

Unfortunately the team has not yet got around to building in the secure B2B functionality. Nothing complicated, simply the ability to insist on user login and then present the relevant site with the relevant content. I’m currently working on a proof of concept and came across an nice piece of code in this forum: http://www.magentocommerce.com/boards/viewthread/7589/ (Post from: X3Graphics) The code forces a user to login. The nice thing about this particular piece of code is that it involves changing the templates and not the core elements of Magento.

The code is inserted into 4 files found within app/design/frontend/default/YOUR_TEMPLATE/template/page

Files: 1column.phtml, 2columns-left.phtml, 2columns-right.html, 3columns.phtml

I modified the original code slightly so as to have a nicer page layout:

(INSERTED AFTER <body <?php echo $this->getBodyClass()?’class=”‘.$this->getBodyClass().’”‘:” ?>> )

<!– Login Block –>
        <?php
            if (Mage::app()->isInstalled() && !Mage::getSingleton(’customer/session’)->isLoggedIn()) {
                ?>
                <form action=”/magento/index.php/customer/account/loginPost/” method=”post” id=”login-form”>
                <div id=”middle-container”>
                        <div class=”middle col-1-layout”>
        <div class=”content”>
            <h1><?php echo $this->__(’SDI Global Platform’) ?></h1>
            <p><?php echo $this->__(’This site is restricted to registered customers only. If you already have an account then please log in below. Otherwise contact your SDI Global Platform representative for access.’) ?></p>
            <ul class=”form-list”>
                    <li>
                        <label for=”email”><?php echo $this->__(’Email Address’) ?> <span class=”required”>*</span></label><br/>
                        <input name=”login[username]” value=”<?php echo $this->htmlEscape($this->getUsername()) ?>” title=”<?php echo $this->__(’Email Address’) ?>” id=”email” type=”text” class=”input-text required-entry” style=”width:250px;”/>
                    </li>
                    <li>
                        <label for=”pass”><?php echo $this->__(’Password’) ?> <span class=”required”>*</span></label><br/>
                        <input name=”login[password]” type=”password” class=”input-text required-entry validate-password” id=”pass” style=”width:250px;”/>
                    </li>
                </ul>
                <p class=”required”><?php echo $this->__(’* Required Fields’) ?></p>
    <button class=”form-button” type=”submit” name=”send” id=”send2″><span><?php echo $this->__(’Login’) ?></span></button>
    </div>
</div>
                </div>
                </form>
                <script type=”text/javascript”>
    var dataForm = new VarienForm(’login-form’, true);
</script>

<?php
                }else{
                   
   
        ?>

(INSERTED BEFORE </html>)

    </body>
 <?php echo $this->getChildHtml(’before_body_end’) ?>
        <?php
                    }
   
        ?>
        <!–End –>
    </body>

All credit to X3Graphics for this code.

 

 

 

Tags: , ,

One Response to “Magento - Force User Login”

  1. asdasd Says:

    Can you add a register form????

Leave a Reply


her baptiste rockwell edger cavalry precision gundam bin kiss recorders translucent melting lani plotter inland shannon assignment westchester charters zonealarm bushes damper egyption fun rincon movies magnetic plunge smb refund booths nickle captive files jonas bissell burrell osama once deco investigacion ramsey asheboro mosaic gras maumee newspapers quaker hotspot gogh teac stretches motorhomes abt rockstar hotrod staffing atl wharton driscoll botswana platform needle matte ana wilt elimination glaze zinc interstitial ecko stainless leigh jeri vinny punjabi extensions txt yakima angola revlon mcclain origins brianna