Exemplo n.º 1
0
 /**
  * 权限判断
  * @param type $type 权限名
  * @param type $json 是否以json返回
  * @param type $return 是否不终止运行
  * @return boolean
  */
 public function checkPower($type, $json = false, $return = false)
 {
     if (Yii::app()->user->isGuest) {
         if ($return) {
             return false;
         } elseif (!$json and !Yii::app()->request->isAjaxRequest) {
             T::message(0, Yii::t('default', 'loginfirst'), Yii::app()->createUrl('site/login'));
         } else {
             T::jsonOutPut(0, Yii::t('default', 'loginfirst'));
         }
     } else {
         $uid = Yii::app()->user->id;
     }
     if ($type == 'login') {
         return true;
     }
     $userinfo = Users::getUserInfo($uid);
     if (!$userinfo) {
         if ($return) {
             return false;
         } elseif (!$json and !Yii::app()->request->isAjaxRequest) {
             T::message(0, '不存在的用户,请核实', Yii::app()->createUrl('site/logout'));
         } else {
             T::jsonOutPut(0, '不存在的用户,请核实');
         }
     }
     $gid = $userinfo['groupid'];
     $groupinfo = UserPower::getInfo($gid);
     if (!$groupinfo) {
         if ($return) {
             return false;
         } elseif (!$json and !Yii::app()->request->isAjaxRequest) {
             T::message(0, '您所在用户组不存在,请核实', Yii::app()->createUrl('site/logout'));
         } else {
             T::jsonOutPut(0, '您所在用户组不存在,请核实');
         }
     }
     $power = GroupPowers::model()->findByAttributes(array('powers' => $type), 'gid=:gid', array(':gid' => $gid));
     if (!$power) {
         $power = GroupPowers::model()->findByAttributes(array('powers' => 'all'), 'gid=:gid', array(':gid' => $gid));
     }
     if (!$power) {
         if ($return) {
             return false;
         } elseif (!$json and !Yii::app()->request->isAjaxRequest) {
             T::message(0, '您所在用户组【' . $groupinfo['title'] . '】无权该操作');
         } else {
             T::jsonOutPut(0, '您所在用户组【' . $groupinfo['title'] . '】无权该操作');
         }
     }
     return true;
 }
Exemplo n.º 2
0
 public static function record($type, $logid = 0)
 {
     if ($type == '') {
         return false;
     }
     if (Yii::app()->user->isGuest) {
         return false;
     }
     $uid = Yii::app()->user->id;
     $desc = GroupPowers::getDesc('admin', $type);
     if ($desc == '') {
         return false;
     }
     $data = array('uid' => $uid, 'logid' => $logid, 'classify' => $type, 'description' => $desc, 'ip' => ip2long(Yii::app()->request->userHostAddress), 'cTime' => time());
     $model = new AdminAction();
     $model->attributes = $data;
     if ($model->save()) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 3
0
 public function adminBar()
 {
     $lang['config']['config'] = array(CHtml::link('基本设置', array('config/index'), array('target' => 'main')), CHtml::link('上传设置', array('config/index', 'type' => 'upload'), array('target' => 'main')), CHtml::link('分页设置', array('config/index', 'type' => 'page'), array('target' => 'main')), CHtml::link('站点信息', array('config/index', 'type' => 'siteinfo'), array('target' => 'main')));
     $lang['content']['columns'] = CHtml::link('栏目', array('columns/index'), array('target' => 'main'));
     $lang['content']['posts'] = CHtml::link('文章', array('posts/index'), array('target' => 'main'));
     $lang['content']['comments'] = CHtml::link('评论', array('comments/index'), array('target' => 'main'));
     $lang['content']['questions'] = CHtml::link('客服', array('questions/index'), array('target' => 'main'));
     $lang['content']['tags'] = CHtml::link('标签', array('tags/index'), array('target' => 'main'));
     $lang['users']['usergroup'] = CHtml::link('用户组', array('users/group'), array('target' => 'main'));
     $lang['users']['users'] = CHtml::link('用户', array('users/index'), array('target' => 'main'));
     $lang['users']['useraction'] = CHtml::link('用户记录', array('users/records'), array('target' => 'main'));
     $lang['link']['link'] = CHtml::link('友链', array('link/index'), array('target' => 'main'));
     $lang['ads']['ads'] = CHtml::link('广告', array('ads/index'), array('target' => 'main'));
     $lang['attachments']['album'] = CHtml::link('相册', array('album/index'), array('target' => 'main'));
     $lang['attachments']['attachments'] = CHtml::link('附件', array('attachments/index'), array('target' => 'main'));
     $main['config'] = CHtml::link('设置', array('config/index'), array('target' => 'main'));
     $main['content'] = CHtml::link('内容', array('columns/index'), array('target' => 'main'));
     $main['users'] = CHtml::link('用户', array('users/group'), array('target' => 'main'));
     $main['link'] = CHtml::link('友链', array('link/index'), array('target' => 'main'));
     $main['ads'] = CHtml::link('广告', array('ads/index'), array('target' => 'main'));
     $main['attachments'] = CHtml::link('附件', array('album/index'), array('target' => 'main'));
     //        $main['']=CHtml::link('',array('/index'));
     //        $main['']=CHtml::link('',array('/index'));
     if (Yii::app()->user->isGuest) {
         if (!$json and !Yii::app()->request->isAjaxRequest) {
             $this->message(0, '请先登录', Yii::app()->createUrl('site/login'));
         } else {
             $this->jsonOutPut(0, '请先登录');
         }
     } else {
         $uid = Yii::app()->user->id;
     }
     $userinfo = Users::model()->findByPk($uid);
     if (!$userinfo) {
         if (!$json and !Yii::app()->request->isAjaxRequest) {
             $this->message(0, '不存在的用户,请核实', Yii::app()->createUrl('site/logout'));
         } else {
             $this->jsonOutPut(0, '不存在的用户,请核实');
         }
     }
     $gid = $userinfo['groupid'];
     $groupinfo = UserGroup::model()->findByPk($gid);
     if (!$groupinfo) {
         if (!$json and !Yii::app()->request->isAjaxRequest) {
             $this->message(0, '该用户所在用户组不存在,请核实', Yii::app()->createUrl('site/logout'));
         } else {
             $this->jsonOutPut(0, '该用户所在用户组不存在,请核实');
         }
     }
     $powers = GroupPowers::model()->findAllByAttributes(array('gid' => $gid));
     $powers = CHtml::listData($powers, 'id', 'powers');
     $allPowers = GroupPowers::getDesc('super');
     $tables = array();
     foreach ($allPowers as $k => $v) {
         foreach ($v['detail'] as $k2 => $v2) {
             if (in_array($k2, $powers)) {
                 $tables[] = $k;
             }
         }
     }
     $tables = array_unique(array_filter($tables));
     $bars = array();
     $mainbars = array();
     foreach ($lang as $l => $v3) {
         foreach ($v3 as $k3 => $v4) {
             if (in_array($k3, $tables)) {
                 $mainbars[] = $l;
                 $bars['seconds'][$l][] = $v4;
             }
         }
     }
     $mainbars = array_unique(array_filter($mainbars));
     foreach ($mainbars as $m => $mv) {
         $bars['firsts'][$mv] = $main[$mv];
     }
     zmf::setFCache("usersBar{$uid}", $bars, 86400);
     return $bars;
 }