Article

Custom Login module creation in Magento

Magento is an open source ecommerce solution. Magento module development have a certain standard procedures. Let us look in to the new custom module creation.
Create one folder local inside app/code/. This local folder is used for our custom module creation. This folder will not affect any upgrade of magento in future if any.
/app/code   |- /core/   |- /community/   |- /local/
Inside this local folder create another folder called as Name Space(Test), inside that folder create another folder, it is usually called as modulename(Mymodule).
App/code/local/Test/Mymodule.
app/code/local/Test/Mymodule/
here Test is our Name Space and Mymodule is our modulename.
 
magento contact button


How to activate the module?
Create a file Test_Mymodule.xml in app/etc/modules/, this will tell Magento to look for and use our custom module.


           true
           local

create config.xml file in app/code/local/Test/Mymodule/etc


            0.1.0
     
        
            
                
                standard
                
                    
                    Test_Mymodule
                    
                    mymodule
                    mymodule.xml
Then create a controller file called as IndexController.php in app/code/local/Test/Mymodule/controllers

inside that file write our indexaction

public function indexAction()
    {
     $this->loadLayout();
     $this->renderLayout();
    }

this will load the layout and render the view file
Create login Action function

public function loginAction()
    {
    	$session = Mage::getSingleton('customer/session');
        if ($session->isLoggedIn()) {
        // is already login redirect to account page
            return;
        }
        $result = array('success' => false);
        if ($this->getRequest()->isPost())
        {
            $login_data = $this->getRequest()->getPost('login');
            if (empty($login_data['username']) || empty($login_data['password'])) {
                $result['error'] = Mage::helper('onepagecheckout')->__('Login and password are required.');
            }
            else
            {
                try
                {
                    $session->login($login_data['username'], $login_data['password']);
                    $result['success'] = true;
                    $result['redirect'] = Mage::getUrl('*/*/index');
                }
                catch (Mage_Core_Exception $e)
                {
                    switch ($e->getCode()) {
                        case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                            $message = Mage::helper('onepagecheckout')->__('Email is not confirmed. Resend confirmation email.', Mage::helper('customer')->getEmailConfirmationUrl($login_data['username']));
                            break;
                        default:
                            $message = $e->getMessage();
                    }
                    $result['error'] = $message;
                    $session->setUsername($login_data['username']);
                }
            }
        }
        $this->_redirect('customer/account/');
        //$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    }

Now let’s create mymodule.xml file in app/design/frontend/default/default/layout/



    
        
            

Create a template file callled as view.phtml in app/design/frontend/default/default/template/mymodule
this is our login form

*

*

create a Block file called as Mymodule.php in app/code/local/Test/Mymodule/Block/  the block folder might not be there, we have to create the same.


type this url in your browser and check the custom login module http://example.com/mymodule where example.com will be your domain name.

Facebook
Twitter
LinkedIn
Categories

Select a Child Category
category
669db96aa2ca1
1
0
226,352,350
Loading....
Recent Posts
Social Links

Related Posts

Want to Learn More?

Milestone experts take the time to listen, understand your needs, and provide the right mix of tools, technology, and resources to help you meet your goals.

Request a complimentary consultation to get started.

Request a Complimentary Consultation

Skip to content