3

I am creating a new module for Facebook Login (no i dont want to use the existing ones) and I am attempting to access/extend the core AccountController.php actions while also adding a new action. The reason I want to extend the AccountController.php class is because I want to register the Facebook user in my custom action and then use some of the functions in the core.

When a user registers, magento uses loginPostAction(). When my Facebook user registers I want to use fbLoginPostAction() in my own AccountController.php in my module and then call some functions in the core AccountController.php.

  • $this->_dispatchRegisterSuccess($customer);
  • $this->_successProcessRegistration($customer);

I've tried several variations but I can't seem to extend the core account controller AND add my custom action. I've been able to extend it and overwrite the existing.

I need to call these functions as I need to dispatch the event after the customer registers.

Am I going about this the right way?

    <?xml version="1.0"?>
    <config>
        <modules>
            <ModEgo_Facebooklogin>
                <version>0.1.0</version>
            </ModEgo_FacebookLogin>
        </modules>
        <frontend>
            <routers>
                <customer>
                    <args>
                        <modules>
                            <modego_facebooklogin before="Mage_Customer">ModEgo_Facebooklogin</modego_facebooklogin>
                        </modules>
                    </args>
                </customer>
            </routers>
        </frontend>          
    </config>    

app/code/local/ModEgo/Facebooklogin/controllers/AccountController.php

    <?php

    require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
    class ModEgo_FacebookLogin_AccountController extends Mage_Customer_AccountController
    {   
        public function fbLoginPostAction() {
            // this new action wont work 
            echo 'hey';
        }
        public function loginPostaction() {
            // this works
            echo 'hey2';
        }
    }
1
  • Did you ever fix this as I am having the same issue... Jun 3, 2015 at 11:19

2 Answers 2

4

By "this new action won't work" I think you meant that you are redirected to login, no? Take a look at Mage_Customer_AccountController::preDispatch():

public function preDispatch()
{
    // a brute-force protection here would be nice

    parent::preDispatch();

    if (!$this->getRequest()->isDispatched()) {
        return;
    }

    $action = $this->getRequest()->getActionName();
    $openActions = array(
        'create',
        'login',
        'logoutsuccess',
        'forgotpassword',
        'forgotpasswordpost',
        'resetpassword',
        'resetpasswordpost',
        'confirm',
        'confirmation'
    );
    $pattern = '/^(' . implode('|', $openActions) . ')/i';

    if (!preg_match($pattern, $action)) {
        if (!$this->_getSession()->authenticate($this)) {
            $this->setFlag('', 'no-dispatch', true);
        }
    } else {
        $this->_getSession()->setNoReferer(true);
    }
}

There's a whitelist of actions which can be accessed without logging in ($openActions). You will need to override the preDispatch() method in your controller class as well, adding your fbLoginPostAction() action to the list.

I wish there were a way to specify these externally :-/

1

Alax there are issue in dispatch function--

    protected $_cookieCheckActions = array('loginPost', 'createpost','fbLoginPost');

       protected $_validActions = array('create','login','logoutSuccess','forgotpassword','forgotpasswordpost','confirm','confirmation','resetpassword','resetpasswordpost');
         /* Please add new function into $customa url 
 protected $_customActions = array('signupformpopup','ajaxloginPost','ajaxCreate','ajaxForgotPassword','logout');
*/
          protected $_customActions = array('fbLoginPost');

         public function preDispatch()
         {
               $action = $this->getRequest()->getActionName();

               if (preg_match('/^('.$this->_getCustomActions().')/i', $action))
               {
                $this->getRequest()->setActionName($this->_validActions[1]);
               }

               parent::preDispatch();

               /**
                * Parent check is complete, reset request action name to origional value
                */
               if ($action != $this->getRequest()->getActionName())
               {
                $this->getRequest()->setActionName($action);
               }

               if (!$this->getRequest()->isDispatched()) {
                return;
               }

               if (!preg_match('/^('.$this->_getValidActions().')/i', $action)) {
                if (!$this->_getSession()->authenticate($this)) {
                 $this->setFlag('', 'no-dispatch', true);
                }
               } else {
                $this->_getSession()->setNoReferer(true);
               }

         }
          protected function _getValidActions()
          {
          return implode("|", array_merge($this->_validActions, $this->_customActions));
          }

         /**
          * Gets custom action names and returns them as a pipe separated string
          *
          * @return string
          */
         protected function _getCustomActions()
         {
          return implode("|", $this->_customActions);
         }

If dispath function only except $_validActions and customActions in routing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.