We have several admin roles for our product and based on that role they could be redirected to a different section for their initial page. That being said I was curious how to redirect an admin user after authentication to a specific page based on their admin role?
2 Answers
Whilst you can configure the startup page on a global scope (System > Configuration > Admin Startup Page
), there is no core functionality to redirect different roles to different places. If you wanted to add such functionality, then rewriting Mage_Admin_Model_User::getStartupPageUrl()
would probably be the way to do it.
rewrite Mage_Adminhtml_Controller_Action
by following code
<admin>
<routers>
<admin_modulename>
<use>admin</use>
<args>
<module>Namespace_Modulename</module>
<frontName>admin_modulename</frontName>
</args>
</admin_modulename>
<adminhtml>
<args>
<modules>
<Namespace_Modulename before="Mage_Adminhtml">Namespace_Modulename_Adminhtml_Admin</Namespace_Modulename>
</modules>
</args>
</adminhtml>
</routers>
</admin>
create IndexController.php
in following path
app/code/local/Namespace/Modulename/Adminhtml/Admin/IndexController.php
class Namespace_Modulename_Adminhtml_Admin_IndexController extends Mage_Adminhtml_Controller_Action
{
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);
}
/* custom code start */
$configValue = Mage::getStoreConfig('sectionName/groupName/fieldName');
if($configValue == 'supplier') // supllier is role name
$url= 'WRITE HERE YOUR URL WHERE YOU WANT TO REDIRECT';
else if($configValue == 'employee') // employee is role name
$url= 'WRITE HERE YOUR URL WHERE YOU WANT TO REDIRECT';
/* custom code end */
$this->_redirect($url);
}
}
If you want to more about Mage::getStoreConfig('sectionName/groupName/fieldName');
then refer this url https://stackoverflow.com/questions/5892476/how-to-get-data-from-magento-system-configuration