/** * 后台首页 */ public function indexAction() { $admin_service = new AdminService(); $admin = $admin_service->checkLogin(); $admin_id = $admin['admin_id']; $department_id = $admin['department_id']; //管理员菜单列表 $admin_menus = $admin_service->getAdminMenus($admin_id, $department_id); //一级菜单 $top_menus = $admin_service->getTopMenu(); $this->view->assign(array('menus' => json_encode($admin_menus), 'top_menus' => json_encode($top_menus), 'admin' => $admin)); }
/** * 权限验证 */ protected function chekcAuth() { $admin_service = new AdminService(); $controller = $this->request->getControllerName(); $action = $this->request->getActionName(); //登录页面和验证码不需要权限验证 if ($controller == 'admin' && ($action == 'login' || $action == 'captcha') || $controller == 'index' || empty($controller)) { return true; } //验证用户是否登录 if ($admin_service->checkLogin() == false) { return $this->redirect('/admin/login'); } if ($admin_service->checkAuth($controller, $action) == false) { if ($this->request->isAjax()) { return $this->showJson(403, '对不起,您没有权限。'); } else { echo "对不起,您没有权限。"; exit; } } }
/** * 权限验证 */ protected function _initAuth() { $admin_service = new AdminService(); $controller = $this->request->getControllerName(); $action = $this->request->getActionName(); //登录页面和验证码不需要权限验证 if ($controller == 'admin' && ($action == 'login' || $action == 'captcha') || $controller == 'index' || empty($controller)) { return true; } //验证用户是否登录 if ($admin_service->checkLogin() == false) { return header('Location: /admin/login'); } if ($admin_service->checkAuth($controller, $action) == false) { if ($this->request->isAjax()) { echo json_encode(array('err' => '403', 'message' => '对不起,您没有权限。')); exit; } else { echo "对不起,您没有权限。"; exit; } } }