/** * 后台控制器初始化 */ protected function _initialize() { // 获取当前用户ID define('UID', is_login()); if (!UID) { // 还没登录 跳转到登录页面 $this->redirect('Public/login'); } /* 读取数据库中的配置 */ $config = S('DB_CONFIG_DATA'); if (!$config) { $config = api('Config/lists'); S('DB_CONFIG_DATA', $config); } C($config); //添加配置 // 是否是超级管理员 define('IS_ROOT', is_administrator()); if (!IS_ROOT && C('ADMIN_ALLOW_IP')) { // 检查IP地址访问 if (!in_array(get_client_ip(), explode(',', C('ADMIN_ALLOW_IP')))) { $this->error('403:禁止访问'); } } import("Common.Util.RedisPool"); $this->redis = \RedisPool::getconnect(); // 检测访问权限 /*$access = $this->accessControl(); if ( $access === false ) { $this->error('403:禁止访问'); }elseif( $access === null ){ $dynamic = $this->checkDynamic();//检测分类栏目有关的各项动态权限 if( $dynamic === null ){ //检测非动态权限 $rule = strtolower(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME); if ( !$this->checkRule($rule,array('in','1,2')) ){ $this->error('未授权访问!'); } }elseif( $dynamic === false ){ $this->error('未授权访问!'); } } */ $this->assign('__MENU__', $this->getMenus()); }
public function _initialize() { import("Common.Util.RedisPool"); $this->redis = \RedisPool::getconnect(); //TODO: 用户登录检测 $not_login = array('Index' => array('index' => 1, 'test' => 1), 'Public' => array('getbaselanguage' => 1, 'gettags' => 1), 'Passport' => array('login' => 1, 'changepwd' => 1, 'ologin' => 1), 'User' => array('index' => 1, 'comment' => 1), 'Reg' => array('getmobilecode' => 1, 'register' => 1), 'Square' => array('topic' => 1, 'nearby' => 1, 'topicuser' => 1, 'charts' => 1), 'Ad' => array('getad' => 1)); if (!$not_login[CONTROLLER_NAME][ACTION_NAME]) { $this->mid = I('post.userId'); $token = I('post.token'); $server_token = $this->redis->GET('Token:uid' . $this->mid); if (!$server_token) { $this->return['code'] = 401; $this->return['message'] = L('token_lose'); $this->goJson($this->return); } elseif ($server_token != $token) { $this->return['code'] = 401; $this->return['message'] = L('token_error'); $this->goJson($this->return); } } }
public function _initialize() { import("Common.Util.RedisPool"); $this->redis = \RedisPool::getconnect(); }