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.















March 16th, 2009 at 7:22 pm
Can you add a register form????