I’m trying to create my own login page which uses Ajax inside a fancybox popup window. I’ve created my own module that extends the default customer AccountController. It seemed to working fine but when user successfully logs ins, the controller saves the customer data in session but when I return to the main page the customer session data no longer exists. Do I need to set the session on return?
My controller is below
public function loginPostAction()
{
$session = Mage::getSingleton('customer/session');
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
Mage::log($login['username'].$login['password']);
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
// Mage::log($session->login($login['username'], $login['password']));
$this->_welcomeCustomer($session->getCustomer(), true);
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), true);
$response = "TRUE";
}
} catch (Mage_Core_Exception $e) {
switch ($e->getCode()) {
case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
$value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
Mage::log("EXCEPTION_EMAIL_NOT_CONFIRMED");
$message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
$response = "This account is not confirmed";
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
$response = "Invalid email or password";
Mage::log("EXCEPTION_INVALID_EMAIL_OR_PASSWORD");
break;
default:
$message = $e->getMessage();
Mage::log("EXCEPTION_default");
}
//$session->addError($message);
Mage::log("about setting the username");
$session->setUsername($login['username']);
} catch (Exception $e) {
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}
} else {
Mage::log("in the else");
$session->addError($this->__('Login and password are required.'));
$response = 'Login and password are required.';
}
}
Mage::log($session->getCustomer());
//echo $response;
//$this->_loginPostRedirect();
}
Any help would be grateful
Fixed by updating the config.xml file. I wasnt overriding the customer controller
<router>
<customer>
<args>
<modules>
<companyname_loginform before="Mage_Customer">companyname_Loginform</companyname_loginform>
</modules>
</args>
</customer>
I found the issue. I was only extending the customer account controller – I wasn’t overriding it correctly from the config.xml