Remember me (id-password) functionality on magento login page.

123

We all know about the login functionality of site. In that functionality one option for remember password available. But magento default does not provide that functionality on login page. So today I post this blog for providing that functionality on page.

 

Step: 1 Open the file at following location.

Magento\app\code\core\Mage\Customer\controllers\AccountController.php

 

Step: 2 Find following function.

protected function _loginPostRedirect()

 

Step: 3 Replace with following function code.


protected function _loginPostRedirect()
{

        $session = $this->_getSession();

        if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl())
        {

               // Set default URL to redirect customer to

               $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl());

             // Redirect customer to the last page visited after logging in

             if ($session->isLoggedIn())
             {
                 if (!Mage::getStoreConfigFlag('customer/startup/redirect_dashboard'))
                 {
                       $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME);
                       if ($referer)
                       {
                                 $referer = Mage::helper('core')->urlDecode($referer);

                                 if ($this->_isUrlInternal($referer))
                                 {
                                       $session->setBeforeAuthUrl($referer);
                                 }
                        }
                }
                else if ($session->getAfterAuthUrl())
                {
                        $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
                }
            }
            else
            {
                $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl());
            }

       }
       else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl())
       {
             $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl());
       }
       else
       {
             if (!$session->getAfterAuthUrl())
             {
                  $session->setAfterAuthUrl($session->getBeforeAuthUrl());
             }

             if ($session->isLoggedIn())
             {
                  $session->setBeforeAuthUrl($session->getAfterAuthUrl(true));
             }
       }

       if ($this->getRequest()->isPost())
       {

             $login = $this->getRequest()->getPost('login');
             $rememberme = $this->getRequest()->getPost('rememberme');

             try
             {

                  $cookie = Mage::getModel('core/cookie');

                  if (!empty($login['username']) && !empty($login['password']) && !empty($rememberme))
                  {
                        $cookie->set('user_name', $login['username']);
                        $cookie->set('pass_user_name', $login['password']);
                        $cookie->set('rememberme', 1);
                  }
                  else if (!empty($login['username']) && !empty($login['password']) && empty($rememberme))
                  {
                        $cookie->delete('user_name');
                        $cookie->delete('pass_user_name');
                        $cookie->delete('rememberme');
                  }
             }
             catch (Exception $e)
             {
             }
       }
       $this->_redirectUrl($session->getBeforeAuthUrl(true));
}

Step: 4 Find following file (login page functionality).

Magento\app\design\frontend\default\[your theme]\template\customer\form\login.phtml

Step: 5 Add following code top of login.phtml.


<?php

          $cooki = Mage::getModel('core/cookie');

          $cookie_user_name = $cooki->get('user_name');

          $cookie_user_password = $cooki->get('pass_user_name');

          $rememberme = $cooki->get('rememberme');

?>

Step: 6 Find following code in login.phtml (user id textbox).


<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" title="<?php echo $this->__('Email Address') ?>" />

And replace with the following code. The code define the user id of user if that user select remember me option.


<input name="login[username]" value="<?php if($cookie_user_name != "){ echo $cookie_user_name;}else{ echo $this-/>htmlEscape($this->getUsername()); } ?>" title="< ?php echo $this->__('Email Address') ?>" id="email" type="text" />

Step: 7 Find following code in login.phtml (password textbox).


<input type="password" name="login[password]" id="pass" title="<?php echo $this->__('Password') ?>" />

And replace with the following code. The code define the password of user if that user select remember me option.


<input name="login[password]" type="password" class="input-text required-entry validate-password"  value="<?php if($cookie_user_password != ''){ echo $cookie_user_password;}?/>" />

Step: 8 Add the following code at the place where you want to display checkbox for the functionality of remember me on page.


<div>

<input type="checkbox" name="rememberme" value="remember" <?php if($rememberme != ''){ echo "checked";} ?/>   /> Remember me.

</div>

I hope this will help you.

Thank you.

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: