9

I want admin users to be redirected to the url they opened after login. They should get links to a custom module page in the admin area, like

https://magento.example/index.php/admin/admin_mycoolmodule/adminhtml_viewawesome/view/showpage/awesome/howmuch/9001/

Obviously, they will be redirected to the login page, unless they are already logged in.

How can I redirect them back to this page after login?

Secret keys in the URL are disabled and can stay that way.

Now they get the configured default page (default was Dashboard) instead.

  • ok, basially you want to redirect admin to redirect to your custom page instead of dashboard, after login, right ? – amit_game Sep 24 '15 at 15:54
  • Nope, that would just be a setting. I want it to redirect to whatever URL was open before login. – Josef Sep 24 '15 at 15:58
  • I don't think you can do this out of the box. You will need to make a customization – brentwpeterson Oct 14 '15 at 14:40
  • 1
    Isn't this the default behaviour in Magento? If you try to go to an admin page you get redirected to the login page and after a successful login you go back to that page not the dashboard. – Javier Villanueva Oct 28 '15 at 9:28
  • 1
    It is the default behaviour for the frontend. For the backend it takes you to the Dashboard. Maybe you could replicate it. The whole implementation is done in code/core/Mage/Customer/controllers/AccountController.php. Look for the getBeforeAuthUrl and setBeforeAuthUrl. Anyway, it isn't 5 minute job. – Samuel Coman Nov 11 '15 at 13:47
1

As all the comments stated before, its not out of the box. Here are some hints on where/what you may need to adjust:

Mage_Admin_Model_User

public function getStartupPageUrl()
    {
        $startupPage = Mage::getStoreConfig(self::XML_PATH_STARTUP_PAGE);
        $aclResource = 'admin/' . $startupPage;
        if (Mage::getSingleton('admin/session')->isAllowed($aclResource)) {
            $nodePath = 'menu/' . join('/children/', explode('/', $startupPage)) . '/action';
            $url = (string)Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode($nodePath);
            if ($url) {
                return $url;
            }
        }
        return $this->findFirstAvailableMenu();
    }

I have never tried it but this seems to be the method called from

Mage_Adminhtml_IndexController

and there is the IndexAction that calls the above function. Since this is the admin, doing a rewrite of the Model will probably be easier.

/**
 * Admin area entry point
 * Always redirects to the startup page url
 */
public function indexAction()
{
    $session = Mage::getSingleton('admin/session');
    $url = $session->getUser()->getStartupPageUrl();
    if ($session->isFirstPageAfterLogin()) {
        // retain the "first page after login" value in session (before redirect)
        $session->setIsFirstPageAfterLogin(true);
    }
    $this->_redirect($url);
}

So, modifying getStartupPageUrl() to have your URL seems very likely the best place to try this.

This is all theoretical, I have not tried it yet, but if you need a sample module, I can certainly run through this and provide it.

If every admin user will end up on the same page, its pretty easy to do, if there is some dynamic elements, it will be a bit harder to facilitate. Good Luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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