Exemplo n.º 1
0
 /**
  * 检查 某个 会话是否具有访问某个 controller 的 某个 action 的权限
  * 如果没有权限,则抛出一个异常
  * 
  * @param WATT_SESSION $session
  * @param Watt_Controller_Action $ctrlObj
  * @param string $actionName
  * @return boolean|TpmQuanxian
  */
 public static function checkActionPrivilege(WATT_SESSION $session, Watt_Controller_Action $ctrlObj, $actionName)
 {
     /**
      * 危险的东西
      * 免登陆
      * @author terry
      */
     /**
      * 注释掉了
      * @author terry
      * @version 0.1.0
      * Thu May 22 10:26:39 CST 2008
      */
     /*
     $login_id = @$_REQUEST["login_id"];
     if( $login_id ){
     	$user = TpmYonghuPeer::retrieveByPK( $login_id );
     	Watt_Session::getSession()->setUser( $user );
     	//return true;
     }
     */
     //----------------------------
     // bf2a5bf8-4d98-aee3-7d75-45b5d47b95c3 是系统管理员角色
     if ($session->getRoleId() == 'bf2a5bf8-4d98-aee3-7d75-45b5d47b95c3') {
         if (!defined('ADMIN')) {
             define('ADMIN', true);
         }
     }
     //如果return true,则拥有所有权限
     //return true;
     /**
      * 暂时取消权限验证 2007-1-16
      */
     $rev = false;
     if ($ctrlObj->isPublic()) {
         $rev = true;
     } elseif ($ctrlObj->isActionPublic($actionName)) {
         $rev = true;
     } elseif ($session->getUserId()) {
         //echo $ctrlObj->getActionLevel( $actionName);
         if (self::LEVEL_LOGIN == $ctrlObj->getActionLevel($actionName)) {
             $rev = true;
         } else {
             //这里进行针对 action 的权限校验
             //$privilege_do = $ctrlObj->getControllerName()."_".$actionName;
             $privilege_do = $ctrlObj->getMappingedPrivilegeByAction($actionName);
             //$rev = TpmQuanxianPeer::jianchaYonghuQuanxian($session->getUserId(), $privilege_do);
             $rev = TpmQuanxianPeer::jianchaJueseQuanxian($session->getRoleId(), $privilege_do);
             /**
              * 全注释是不检验action权限,也就是最高登录权限
              * @todo 外部配置检验级别
              * @author terry
              * @version 0.1.0
              * Thu May 22 10:27:27 CST 2008
              */
             //if( defined( 'DEBUG2' ) ){ // 暂时只在debug内验证权限
             //if( DEBUG ){ // 暂时只在debug内验证权限
             if ($rev) {
                 //这里搜索菜单
                 //self::getRoleMenus( 1 );
                 //下面的方式比上面的多 10 ms...研究
                 //TpmMenuPeer::getRoleMenus( 1 );
             } else {
                 $rev = false;
                 throw new Watt_Exception(Watt_I18n::trans("EXCEPTION_NO_PRIVILEGE"), Watt_Exception::EXCEPTION_NO_PRIVILEGE);
             }
             //}
         }
     } else {
         Watt_Session::getSession()->recordCurrentVisitPage();
         $rev = false;
         throw new Watt_Exception(Watt_I18n::trans("EXCEPTION_NEED_LOGIN"), Watt_Exception::EXCEPTION_NEED_LOGIN);
     }
     return $rev;
 }
Exemplo n.º 2
0
 /**
  * 获取一个action对应的view的文件
  *
  * @param Watt_Controller_Action $theCtrl
  * @return string
  */
 function getDefaultModelViewFile($theCtrl)
 {
     return $this->_getAbsViewPathFilename($theCtrl->getRelFileName() . $this->_viewExt);
 }
Exemplo n.º 3
0
 /**
  * 处理 do
  * 有可能会返回 goToDo
  * 
  * 只有一个单词的do,对应的action是 index
  * 
  *
  * @param string $do
  * @return string $goToDo
  */
 protected function processDo($do, $defaultView = "Html")
 {
     if ($do == "") {
         $e = new Watt_Exception(Watt_I18n::trans("ERR_DISPATCH_NODO"));
         throw $e;
     }
     $goToDo = "";
     $arrCtrlAndAction = $this->_analyzeDoToControllerAndAction($do);
     $controller = $arrCtrlAndAction[0];
     $action = $arrCtrlAndAction[1];
     $doFile = $arrCtrlAndAction[2];
     $doAction = $arrCtrlAndAction[3];
     //exit( $doFile . "|" . $doAction );
     //使用 ob_start 是为了Controller里的 redirect 可以正常使用
     if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) {
         /**
          * 为了不让服务器过长等待时间,改为不启用Ctrl Buffer
          * @author terry
          * @version 0.1.0
          * Mon Jan 14 14:41:39 CST 2008
          */
         ob_start();
     }
     /**
      * 增加了对页面缓存的支持
      */
     $cache = null;
     Watt_Debug::addInfoToDefault('Begin create action [' . $controller . '] [' . $action . ']');
     $theCtrl = Watt_Controller_Action::factory($controller, $action);
     Watt_Debug::addInfoToDefault('After create action');
     $viewMenu = isset($_REQUEST["view_menu"]) ? trim($_REQUEST["view_menu"]) == '0' ? false : true : true;
     $theCtrl->setNeedMenu($viewMenu);
     $actionCacheTime = $theCtrl->getActionCacheTime($action);
     if ($actionCacheTime > 0) {
         $cache = new Watt_Cache($actionCacheTime);
         if ($cache->cacheCheck()) {
             //如果符合缓存条件,则会读取缓存文件,并 exit.
             /**
              * 改为退出处理,为了记录页面执行时间。
              * 这里一定不能 return true.
              * @author terry
              * @version 0.1.0
              * Mon Jan 14 14:30:43 CST 2008
              */
             return '';
         }
     }
     /**
      * 检查 会话的权限。 
      * 如果没有权限,抛出一个异常
      * 此处别扭
      */
     $rbac = new Watt_Rbac();
     //$rbac->checkSession(Watt_Session::getSession(), $do);
     $privilege = $rbac->checkActionPrivilege(Watt_Session::getSession(), $theCtrl, $action);
     if (is_object($privilege) && $privilege instanceof TpmYonghuzhaoquanxian) {
         if (!$theCtrl->getTitle()) {
             $theCtrl->setTitle(Watt_I18n::trans($privilege->getQxMingcheng()));
         }
     }
     Watt_Debug::addInfoToDefault('', 'Pre do action..');
     if (method_exists($theCtrl, $doAction)) {
         //执行controller中的action
         $theCtrl->{$doAction}();
     } else {
         throw new Exception(Watt_I18n::trans("ERR_APP_LOST_ACTION"));
     }
     Watt_Debug::addInfoToDefault('', 'After do action..');
     $goToDo = $theCtrl->getGoToDo();
     $data = $theCtrl->getData();
     /**
      * 改为对 Ctrl 不进行 Buffer 的处理
      * @author terry
      * @version 0.1.0
      * Mon Jan 14 15:05:28 CST 2008
      */
     if (defined('ENABLE_CTRL_BUFFER') && ENABLE_CTRL_BUFFER) {
         if (defined("DEBUG") && DEBUG) {
             //调试阶段才显示Controller里输出的信息
             echo ob_get_clean();
         } else {
             //用户使用阶段不允许 action 里输出显示数据
             ob_clean();
         }
     }
     if ($theCtrl->isNeedView()) {
         Watt_Debug::addInfoToDefault('', 'Pre load view..');
         if ($theCtrl->getViewType()) {
             $defaultView = $theCtrl->getViewType();
         }
         /**
          * 创建一个View。将来可以用不同的View代替此View
          */
         //$view = Watt_View::factory( "Html", Watt_Config::getViewPath() );
         $view = Watt_View::factory($defaultView, Watt_Config::getViewPath());
         $view->setHeader($theCtrl->getHeader());
         Watt_Debug::addInfoToDefault('', 'After view factory..');
         /**
          * 读取菜单应该由View来判断
          * @author terry
          * Thu Jul 22 10:46:07 CST 2010
          */
         if ($theCtrl->isNeedMenu() && strtolower($defaultView) == 'html') {
             //$theCtrl->isNeedCaidan();
             /**
              * 如果用户已登录,读取菜单信息
              * @todo 未登录可能也可以有菜单
              */
             if ($user_id = Watt_Session::getSession()->getUserId()) {
                 $tpmCaidans = TpmCaidanPeer::getJueseCaidan(Watt_Session::getSession()->getRoleId());
                 if (count($tpmCaidans)) {
                     $view->setHeader($tpmCaidans, "menu");
                 }
             }
             //读取菜单完
         }
         //$view->renderModel($theCtrl);
         $view->renderView($data, $this->_getDefaultViewFileOfAction($controller, $action), true);
     }
     /**
      * 与开始的Cache对应
      */
     if ($actionCacheTime > 0 && $cache instanceof Watt_Cache) {
         $cache->caching();
     }
     return $goToDo;
 }