checkAuth($route, Session::get('adminuser.roleid'))) { $this->error('您无此操作权限!'); } // 进行操作日志的记录 $this->syslogRecord($route); // 中间件handle方法的返回值必须是一个Response对象。 return $next($request); } protected function syslogRecord($route = '') { // 定义方法白名单(不记录日志) $allow = [ ]; $action = Request::action(); if ($action != 'index' && !in_array($route, $allow) && !(Request::isGet())) { \app\model\SysLog::record($route); } } /** * 检查权限 * @param string|array $route 需要验证的规则列表,支持逗号分隔的权限规则或索引数组 * @param integer $rid 认证用户角色ID * @return boolean 通过验证返回true;失败返回false */ public function checkAuth($route, $rid) { // 超级管理员不检查权限 if ($rid==1) { return true; } $menus = \app\model\SysMenu::getUserMenuList($rid); if (!Config::get('app.auth_on')) { return true; } // 定义方法白名单 $allow = [ 'index/index', // 首页 'index/usedspace', // 使用空间 'index/clearcache', // 清除缓存 'file_manager/uploadImage', // 图片上传 'file_manager/ckeditorUploadImage', // 图片上传 ]; // 查询所有不验证的方法并放入白名单 $menuOpen = \app\model\SysMenu::where('open', 1)->column('url'); $allow = array_merge($allow, $menuOpen); foreach ($menus as $value) { if ($value->type == 0) { continue; } $allow[] = $value->url; } $allow = array_unique($allow); if (in_array($route, $allow)) { return true; } return false; } /** * 操作错误跳转的快捷方法 抽的 liliuwei Jump error 方法 * @access protected * @param mixed $msg 提示信息 * @return void */ protected function error($msg = '') { $url = Request::isAjax() ? '' : 'javascript:history.back(-1);'; $result = [ 'code' => 0, 'msg' => $msg, 'data' => '', 'url' => $url, 'wait' => 3, ]; $type = Request::isJson() || Request::isAjax() ? 'json' : 'html';; if ('html' == strtolower($type)) { $dispatch_error_tmpl = app()->getRootPath().'/vendor/liliuwei/thinkphp-jump/src/tpl/dispatch_jump.tpl'; View::assign($result); View::engine()->layout(false); $data = View::fetch($dispatch_error_tmpl); $response = Response::create($data, $type); } else { $response = Response::create($result, $type); } throw new HttpResponseException($response); } }