douzhaolu4780 2014-05-21 13:44
浏览 99
已采纳

如何在自定义路由上验证用户是否为管理员或客户的匹配功能

I needed to know who is accessing a particular route is logged and if it is a customer or admin User, any idea how to do that on match function controllador route?

Code of the custom route controller:

class Ceicom_Boleto_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract
{
    public function initControllerRouters($observer)
    {
        $front = $observer->getEvent()->getFront();
        $boleto = new Ceicom_Boleto_Controller_Router();
        $front->addRouter('boleto',$boleto);
    }
    public function match(Zend_Controller_Request_Http $request)
    {
       /*
         if is admin and is logged
       */
       Mage::app()->getFrontController()->getResponse()
                  ->setRedirect("/boleto/admin/view/")
                  ->sendResponse();
       exit;
      /*
         if is user and is logged
      */
       Mage::app()->getFrontController()->getResponse()
                  ->setRedirect("/boleto/user/view/")
                  ->sendResponse();
       exit;

    }
}
  • 写回答

2条回答 默认 最新

  • dtfbj24048 2014-05-21 14:24
    关注

    try this code:

    class Ceicom_Boleto_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract
    {
        public function initControllerRouters($observer)
        {
            $front = $observer->getEvent()->getFront();
            $boleto = new Ceicom_Boleto_Controller_Router();
            $front->addRouter('boleto',$boleto);
        }
        public function match(Zend_Controller_Request_Http $request)
        {
           /*
             if is admin and is logged
           */
            //get the admin session
            Mage::getSingleton('core/session', array('name'=>'adminhtml'));
            //verify if the user is logged in to the backend
            if(Mage::getSingleton('admin/session')->isLoggedIn()){
    
               Mage::app()->getFrontController()->getResponse()
                          ->setRedirect("/boleto/admin/view/")
                          ->sendResponse();
               exit;
           }
    
          /*
             if is user and is logged
          */
          if(Mage::getSingleton('customer/session')->isLoggedIn()){
               Mage::app()->getFrontController()->getResponse()
                          ->setRedirect("/boleto/user/view/")
                          ->sendResponse();
               exit;
           }
    
        }
    }
    

    Hope this helps! All the best :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题