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