123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace Common\Controller;
- use Think\Controller;
- use Think\Auth;
- use Common;
- //权限认证
- class AuthController extends BaseController {
- protected $site_url;
- public function __construct() {
- parent::__construct();
- $common = new Common\Common\Common();
- $common->auto_load_func('Application/Common/Server/'); //自动导入Server
- $common->auto_load_func('Application/Common/Common/util/'); //自动导入工具类(自己写的)
- $this->site_url = SITE_URL;
- $admin = self::get_my_info();
- //自动运行,为了判断左侧导航、右侧导航的选中状态,S为导航ID
- cookie('s',I('s'),86400);
- //session不存在时,不允许直接访问
- if(!$admin['aid']){
- $this->error('还没有登录,正在跳转到登录页',U('Admin/Login/login'));
- }
- //session存在时,不需要验证的权限
- $not_check = array('Index/index','Index/panel','Login/login','Common/base64_upload','Common/file_upload','Common/img_upyun','Common/upload_upyun');
- //当前操作的请求 模块名/方法名
- if(in_array(CONTROLLER_NAME.'/'.ACTION_NAME, $not_check)){
- return true;
- }
- //下面代码动态判断权限
- $auth = new Auth();
- if(!$auth->check(CONTROLLER_NAME.'/'.ACTION_NAME,$admin['aid'])){
- $this->error('没有权限');
- }
- }
- /**
- * get封装
- * @param type $get
- * $defalut默认值 默认null
- */
- public function myGet($get, $defalut = null) {
- $result = $_GET[$get];
- !empty($result) ? ($result = $result) : ($result = $defalut);
- $result = htmlspecialchars($result);
- return $result;
- }
- /**
- * post封装
- * @param type $post
- */
- public function myPost($post, $defalut = null) {
- $result = $_POST[$post];
- !empty($result) ? ($result = $result) : ($result = $defalut);
- $result = htmlspecialchars($result);
- return $result;
- }
- /**
- * $request封装
- * @param type $request
- * @param type $default
- * @return type
- */
- public function myRequest($request, $defalut = null) {
- $result = $_REQUEST[$request];
- !empty($result) ? ($result = $result) : ($result = $defalut);
- $result = htmlspecialchars($result);
- return $result;
- }
- //空操作
- public function _empty() {
- header("HTTP/1.0 404 Not Found");
- $this->assign('info', 'baseAction/_empty');
- $this->display('./Tpl/404.html');
- exit;
- }
- /**
- * 自动加载函数库 .php文件
- * @param string $path 文件夹
- */
- public function auto_load_func($path) {
- $auto_funcs = glob($path . "*.php");
- if (!empty($auto_funcs)) {
- foreach ($auto_funcs as $fileName) {
- include_once $fileName;
- }
- }
- }
- /**
- * 返回并重载上一页
- * Transient_1988
- */
- public function goBack() {
- echo '<script>location.href = document.referrer;</script>';
- exit;
- }
- /**
- * 保存登录信息
- * @param array $info
- * @param int $time
- */
- static public function set_my_info($info) {
- session('admin_motion', $info);
- }
- /**
- * 获取保存的登录信息
- */
- static public function get_my_info(){
- return session('admin_motion');
- }
- /**
- * 清除登录信息
- */
- static public function del_my_info(){
- session('admin_motion', null);
- }
- /**
- * 获取面包屑
- * @return array
- */
- static function get_bread_crumbs(){
- $name = CONTROLLER_NAME . '/' . ACTION_NAME ;
- $where = array('name' => $name);
- $field = 'id,name,title,pid';
- $model = M('auth_rule');
- $data = array();
- $temp = $model->where($where)->field($field)->find();
- while(!empty($temp)){
- $data[] = $temp;
- $where = array('id' => $temp['pid']);
- $temp = $model->where($where)->field($field)->find();
- }
- $data = array_reverse($data);
- return $data;
- }
- }
- ?>
|