Пример #1
0
 /**
  * 获取用户可访问的权限
  * @return array('status'=>0,'msg'=>'','data'=>array(),'user_type'=>0) 成功status为1 有data数据,用户权限
  */
 static function getPowerAll()
 {
     $ret = array('status' => 0, 'msg' => '');
     try {
         if (!isset($_SESSION['user_id'])) {
             throw new Exception('用户ID不能为空');
         }
         $userid = $_SESSION['user_id'];
         $ret_judge_bool = permission::judgeUserIP();
         //获取用户是否需要判断来源IP
         if ($ret_judge_bool['status'] == 0) {
             throw new Exception($ret_judge_bool['msg']);
         }
         if ($ret_judge_bool['is_bool_ip']) {
             //需要判断来源IP
             $ret_ip = self::getIpLimit($userid);
             //获取用户的IP白名单
             if ($ret_ip['status'] == 0 && !isset($ret_ip['data'])) {
                 throw new Exception($ret_ip['msg']);
             }
             $is_bool = false;
             foreach ($ret_ip['data'] as $value) {
                 if ($value['IP'] == Comm::getSourceIp()) {
                     $is_bool = true;
                     break;
                 }
             }
             if (!$is_bool) {
                 //未在IP白名单里找到来源IP
                 throw new Exception('来源IP未添加到用户的IP白名单里');
             }
         }
         $user_type = $ret_judge_bool['user_type'];
         //用户权限级别
         if ($user_type != 1) {
             //不为超级管理员时才查询其访问权限
             $cache = Yii::app()->cache->get(CacheName::getCacheName('user_action_Info') . $userid . $user_type);
             if ($cache === false) {
                 $ret_Action = self::getActionInfoByUser($userid, $user_type);
                 if ($ret_Action['status'] == 0) {
                     throw new Exception($ret_Action['msg']);
                 }
                 Yii::app()->cache->set(CacheName::getCacheName('user_action_Info') . $userid . $user_type, $ret_Action, 300);
                 //设置用户的可访问页面列表缓存
             } else {
                 $ret_Action = $cache;
             }
             if ($user_type == Yii::app()->params['main_type'] && $_SESSION['sub_id'] != 0) {
                 //当期帐号权限为总屏权限时,并且切换到了子屏
                 $ret_Action = self::getActionInfoByUser($_SESSION['sub_id'], Yii::app()->params['sub_type']);
                 //获取子屏访问权限
             }
             $ret['data'] = $ret_Action['data'];
         }
         $ret['status'] = 1;
         $ret['user_type'] = $user_type;
     } catch (Exception $e) {
         $ret['msg'] = $e->getMessage();
     }
     return $ret;
 }