when I select the require email confirmation No in customer configuration in magento admin panel , in accountcontroller.php changed
/////
class Mage_Customer_AccountController extends Mage_Core_Controller_Front_Action {
protected $_cookieCheckActions = array('loginPost', 'createpost');
protected function _getSession()
{
return Mage::getSingleton('customer/session');
}
public function preDispatch()
{
// a brute-force protection here would be nice
parent::preDispatch();
if (!$this->getRequest()->isDispatched()) {
return;
}
$action = $this->getRequest()->getActionName();
$pattern = '/^(create|login|logoutSuccess|forgotpassword|forgotpasswordpost|confirm|confirmation)/i';
if (!preg_match($pattern, $action)) {
if (!$this->_getSession()->authenticate($this)) {
$this->setFlag('', 'no-dispatch', true);
}
} else {
$this->_getSession()->setNoReferer(true);
}
}
/**
* Action postdispatch
*
* Remove No-referer flag from customer session after each action
*/
public function postDispatch()
{
parent::postDispatch();
$this->_getSession()->unsNoReferer(false);
}
public function indexAction()
{
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->getLayout()->getBlock('content')->append(
$this->getLayout()->createBlock('customer/account_dashboard')
);
$this->getLayout()->getBlock('head')->setTitle($this->__('My Account'));
$this->renderLayout();
}
/**
* Customer login form page
*/
public function loginAction()
{
if ($this->_getSession()->isLoggedIn()) {
//$this->_redirect('registration-success');
//Mage::getUrl('registration-success', array('_secure'=>true));
$this->_redirect('*/*/');
return;
}
$this->getResponse()->setHeader('Login-Required', 'true');
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->renderLayout();
}
/**
* Login post action
*/
public function loginPostAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$login = $this->getRequest()->getPost('login');
if (!empty($login['username']) && !empty($login['password'])) {
try {
$session->login($login['username'], $login['password']);
if ($session->getCustomer()->getIsJustConfirmed()) {
$this->_welcomeCustomer($session->getCustomer(), 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']);
$message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
break;
case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
$message = $e->getMessage();
break;
default:
$message = $e->getMessage();
}
$session->addError($message);
$session->setUsername($login['username']);
} catch (Exception $e) {
// Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
}
} else {
$session->addError($this->__('Login and password are required.'));
}
}
$this->_loginPostRedirect();
}
/**
* Define target URL and redirect customer after logging in
*/
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());
$session->setBeforeAuthUrl('/marketplacepartner/partnerproducts/mydashboard/');
// Redirect customer to the last page visited after logging in
if ($session->isLoggedIn()) {
if (!Mage::getStoreConfigFlag(
Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_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));
}
}
$this->_redirectUrl($session->getBeforeAuthUrl(true));
}
/**
* Customer logout action
*/
public function logoutAction()
{
$this->_getSession()->logout()
->setBeforeAuthUrl(Mage::getUrl());
// $this->_redirect('registration-success');
$this->_redirect('*/*/logoutSuccess');
}
/**
* Logout success page
*/
public function logoutSuccessAction()
{
$this->loadLayout();
$this->renderLayout();
}
/**
* Customer register form page
*/
public function createAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('registration-success');
// $this->_redirect('*/*');
return;
}
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->renderLayout();
}
/**
* Create customer account action
*/
public function createPostAction()
{
$session = $this->_getSession();
if ($session->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$session->setEscapeMessages(true); // prevent XSS injection in user input
if ($this->getRequest()->isPost()) {
$errors = array();
if (!$customer = Mage::registry('current_customer')) {
$customer = Mage::getModel('customer/customer')->setId(null);
}
/* @var $customerForm Mage_Customer_Model_Form */
$customerForm = Mage::getModel('customer/form');
$customerForm->setFormCode('customer_account_create')
->setEntity($customer);
$customerData = $customerForm->extractData($this->getRequest());
if ($this->getRequest()->getParam('is_subscribed', false)) {
$customer->setIsSubscribed(1);
}
/**
* Initialize customer group id
*/
$customer->getGroupId();
if ($this->getRequest()->getPost('create_address')) {
/* @var $address Mage_Customer_Model_Address */
$address = Mage::getModel('customer/address');
/* @var $addressForm Mage_Customer_Model_Form */
$addressForm = Mage::getModel('customer/form');
$addressForm->setFormCode('customer_register_address')
->setEntity($address);
$addressData = $addressForm->extractData($this->getRequest(), 'address', false);
$addressErrors = $addressForm->validateData($addressData);
if ($addressErrors === true) {
$address->setId(null)
->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));
$addressForm->compactData($addressData);
$customer->addAddress($address);
$addressErrors = $address->validate();
if (is_array($addressErrors)) {
$errors = array_merge($errors, $addressErrors);
}
} else {
$errors = array_merge($errors, $addressErrors);
}
}
try {
$customerErrors = $customerForm->validateData($customerData);
if ($customerErrors !== true) {
$errors = array_merge($customerErrors, $errors);
} else {
$customerForm->compactData($customerData);
$customer->setPassword($this->getRequest()->getPost('password'));
$customer->setConfirmation($this->getRequest()->getPost('confirmation'));
$customerErrors = $customer->validate();
if (is_array($customerErrors)) {
$errors = array_merge($customerErrors, $errors);
}
}
$validationResult = count($errors) == 0;
if (true === $validationResult) {
$customer->save();
Mage::dispatchEvent('customer_register_success',
array('account_controller' => $this, 'customer' => $customer)
);
if ($customer->isConfirmationRequired()) {
$customer->sendNewAccountEmail(
'confirmation',
$session->getBeforeAuthUrl(),
Mage::app()->getStore()->getId()
);
$session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
$this->_redirect('registration-success', array('_secure'=>true));
//$this->_redirectSuccess(Mage::getUrl('registration-success', array('_secure'=>true)));
// $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure'=>true)));
return;
$session->addSuccess($this->__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%s">click here</a>.', Mage::helper('customer')->getEmailConfirmationUrl($customer->getEmail())));
} else {
$session->setCustomerAsLoggedIn($customer);
$url = $this->_welcomeCustomer($customer);
$this->_redirectSuccess($url);
return;
}
} else {
$session->setCustomerFormData($this->getRequest()->getPost());
if (is_array($errors)) {
foreach ($errors as $errorMessage) {
$session->addError($errorMessage);
}
} else {
$session->addError($this->__('Invalid customer data'));
}
}
} catch (Mage_Core_Exception $e) {
$session->setCustomerFormData($this->getRequest()->getPost());
if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
$url = Mage::getUrl('customer/account/forgotpassword');
$message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
$session->setEscapeMessages(false);
} else {
$message = $e->getMessage();
}
$session->addError($message);
} catch (Exception $e) {
$session->setCustomerFormData($this->getRequest()->getPost())
->addException($e, $this->__('Cannot save the customer.'));
}
}
$this->_redirectError(Mage::getUrl('*/*/create', array('_secure' => true)));
}
/**
* Add welcome message and send new account email.
* Returns success URL
*
* @param Mage_Customer_Model_Customer $customer
* @param bool $isJustConfirmed
* @return string
*/
protected function _welcomeCustomer(Mage_Customer_Model_Customer $customer, $isJustConfirmed = false)
{
$this->_getSession()->addSuccess(
$this->__('Thank you for registering with %s.', Mage::app()->getStore()->getFrontendName())
);
$customer->sendNewAccountEmail(
$isJustConfirmed ? 'confirmed' : 'registered',
'',
Mage::app()->getStore()->getId()
);
if ($this->_getSession()->getBeforeAuthUrl()) {
$successUrl = $this->_getSession()->getBeforeAuthUrl(true);
}
$successUrl = Mage::getUrl('registration-success', array('_secure'=>true));
return $successUrl;
}
/**
* Confirm customer account by id and confirmation key
*/
public function confirmAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
try {
$id = $this->getRequest()->getParam('id', false);
$key = $this->getRequest()->getParam('key', false);
$backUrl = $this->getRequest()->getParam('back_url', false);
if (empty($id) || empty($key)) {
throw new Exception($this->__('Bad request.'));
}
// load customer by id (try/catch in case if it throws exceptions)
try {
$customer = Mage::getModel('customer/customer')->load($id);
if ((!$customer) || (!$customer->getId())) {
throw new Exception('Failed to load customer by id.');
}
}
catch (Exception $e) {
throw new Exception($this->__('Wrong customer account specified.'));
}
// check if it is inactive
if ($customer->getConfirmation()) {
if ($customer->getConfirmation() !== $key) {
throw new Exception($this->__('Wrong confirmation key.'));
}
// activate customer
try {
$customer->setConfirmation(null);
$customer->save();
}
catch (Exception $e) {
throw new Exception($this->__('Failed to confirm customer account.'));
}
// log in and send greeting email, then die happy
$this->_getSession()->setCustomerAsLoggedIn($customer);
$successUrl = $this->_welcomeCustomer($customer, true);
$this->_redirectSuccess(Mage::getUrl('registration-success', array('_secure'=>true)));
// $this->_redirectSuccess($backUrl ? $backUrl : $successUrl);
return;
}
//$this->_redirect('registration-success'); // die happy $this->_redirectSuccess(Mage::getUrl('registration-success', array('_secure'=>true))); return; } catch (Exception $e) { // die unhappy $this->_getSession()->addError($e->getMessage()); $this->_redirectError(Mage::getUrl('//index', array('_secure'=>true))); return; } }
/**
* Send confirmation link to specified email
*/
public function confirmationAction()
{
$customer = Mage::getModel('customer/customer');
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
// try to confirm by email
$email = $this->getRequest()->getPost('email');
if ($email) {
try {
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId())->loadByEmail($email);
if (!$customer->getId()) {
throw new Exception('');
}
if ($customer->getConfirmation()) {
$customer->sendNewAccountEmail('confirmation', '', Mage::app()->getStore()->getId());
$this->_getSession()->addSuccess($this->__('Please, check your email for confirmation key.'));
} else {
$this->_getSession()->addSuccess($this->__('This email does not require confirmation.'));
}
$this->_getSession()->setUsername($email);
$this->_redirectSuccess(Mage::getUrl('registration-success', array('_secure' => true)));
//$this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure' => true)));
} catch (Exception $e) {
$this->_getSession()->addException($e, $this->__('Wrong email.'));
$this->_redirectError(Mage::getUrl('*/*/*', array('email' => $email, '_secure' => true)));
}
return;
}
// output form
$this->loadLayout();
$this->getLayout()->getBlock('accountConfirmation')
->setEmail($this->getRequest()->getParam('email', $email));
$this->_initLayoutMessages('customer/session');
$this->renderLayout();
}
/**
* Forgot customer password page
*/
public function forgotPasswordAction()
{
$this->loadLayout();
$this->getLayout()->getBlock('forgotPassword')->setEmailValue(
$this->_getSession()->getForgottenEmail()
);
$this->_getSession()->unsForgottenEmail();
$this->_initLayoutMessages('customer/session');
$this->renderLayout();
}
if ($this->_getSession()->getBeforeAuthUrl()) {
$successUrl = $this->_getSession()->getBeforeAuthUrl(true);
}
$successUrl = Mage::getUrl('registration-success', array('_secure'=>true));
return $successUrl;
Above code is working fine for redirect to cms page (without email confirmation option NO).
But I want to redirect to cms page when the require email confirmation option is YES.