Mini Login Form Magento
Hi,
[Magento Version 1.4.1.1]
Magento provides a small login form that the user could use without navigating away from his current page, we can see this in customer.xml layout:
<!--
Load this update on every page when customer is logged in
-->
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
</reference>
</customer_logged_in>
<!--
Load this update on every page when customer is logged out
-->
<customer_logged_out>
<reference name="right">
<block type="customer/form_login" name="customer_form_mini_login" before="-" template="customer/form/mini.login.phtml"/>
</reference>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
</reference>
<remove name="wishlist_sidebar"></remove>
<remove name="reorder"></remove>
</customer_logged_out>
We are using the mini login form on the homepage, and we needed a way to display a different message depending on the user login status, the default behavior was to hide the whole form (we can see that the block is missing from the customer_logged_in login tag).
We change the mini form template to fit our needs as follows:
/app/design/frontend/default/default/template/customer/form/mini.login.phtml
<?php $rLoggedIn = $this->helper('customer')->isLoggedIn(); ?>
<div class="block block-login">
<div class="block-title">
<strong><span><?php echo $rLoggedIn ? 'WELCOMe' : $this->__('Login') ?></span></strong>
</div>
<?php if ($rLoggedIn) { ?>
<p class="welcome-msg" style="margin: 15px;">
Welcome back <strong><?php echo Mage::getSingleton('customer/session')->getCustomer()->getFirstname(); ?></strong>, <br /><br />
Browse to your <a href="<?php echo $this->getUrl('customer/account') ?>">Dashboard</a>
</p>
<?php } else { ?>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post">
<div class="block-content">
<label for="mini-login"><?php echo $this->__('Email:') ?></label><input type="text" name="login[username]" id="mini-login" class="input-text" />
<label for="mini-password"><?php echo $this->__('Password:') ?></label><input type="password" name="login[password]" id="mini-password" class="input-text" />
<div class="actions">
<button type="submit" class="button"><span><span><?php echo $this->__('Login') ?></span></span></button>
</div>
</div>
</form>
<?php } ?>
</div>
Hope that helps.