public function Action_index() { // 检测用户是否登录 if (AdminController::isLogin()) { return CResponse::getInstance()->redirect(array('c' => 'admin', 'a' => 'index')); } if ($_POST) { // 获取参数 $username = $this->Args('username', 'string'); $password = $this->Args('password', 'string'); // 检查登陆 $userCheckStatus = CModel::factory('adminUserModel')->userCheck($username, $password); // 检查失败 if (false == $userCheckStatus['status']) { // 登录失败 $this->assign('userLoginStatus', $userCheckStatus); } else { // 允许登陆 $userLoginStatus = CModel::factory('adminUserModel')->userLogin($userCheckStatus); if ($userLoginStatus['status'] == false) { $this->assign('userLoginStatus', $userLoginStatus); } else { // 登录成功 CResponse::getInstance()->redirect($userLoginStatus['urlPram']); } } } $this->display(); }
protected function displayList($model, $where) { // 用户列表 $list = CModel::factory($model)->getList($where); $this->assign('list', $list); // 分页 $count = CModel::factory($model)->getCount($where); if (!empty($list)) { $pageObject = new Pagination($count, CModel::factory($model)->pageRows); $pagestr = $pageObject->fpage(array(3, 4, 5, 6, 7)); $this->assign('page', $pagestr); } $this->assign('count', $count); $this->assign('where', $where); $this->display(); }
/** * 返回符合用户权限的菜单 */ public static function getUserMenu($userData) { // 超级管理员不校验权限 if (isset($userData['groupId']) && 1 == $userData['groupId']) { return array('menu' => self::_getAllMenu(), 'allRight' => array()); } // 若不存在权限资源则丢弃 if (!isset($userData['groupData']['rightList'])) { return array(); } // 所有权限列表 $rights = CModel::factory('adminRightsModel')->listKey(); // 用户资源ID $userRightIDList = isset($userData['groupData']['rightList']) ? explode(',', $userData['groupData']['rightList']) : array(); // 将用户的资源ID 换成资源 $userRightList = array(); foreach ($userRightIDList as $val) { if (isset($rights[$val])) { $rightString = $rights[$val]['content']; $rightArr = explode(',', $rightString); $userRightList = array_merge($rightArr, $userRightList); } } // 全部菜单 $menuList = self::_getAllMenu(); // 移除不被允许的菜单 foreach ((array) $menuList as $firstKey => $firstMenu) { foreach ((array) $firstMenu['list'] as $secKey => $secMenu) { if (!isset($secMenu['c']) || !isset($secMenu['a'])) { unset($menuList[$firstKey]['list'][$secKey]); continue; } $thisRightStr = $secMenu['c'] . '@' . $secMenu['a']; if (!in_array($thisRightStr, $userRightList)) { unset($menuList[$firstKey]['list'][$secKey]); } } } // 去掉空选项 foreach ((array) $menuList as $lvKey => $val) { if (empty($val['list'])) { unset($menuList[$lvKey]); } } // 得到合法菜单 return array('menu' => $menuList, 'allRight' => $userRightList); }
/** * 用户登陆 */ public function userLogin($checkData) { $result = array('status' => false, 'message' => '发生错误,处理失败'); // 检查 if (!isset($checkData['status']) || false == $checkData['status'] || empty($checkData['userData'])) { $result['message'] = '登录失败'; return $result; } // 用户资料 $userData = $checkData['userData']; // 获取权限 $groupList = CModel::factory('adminUserGroupModel')->getGroupList(); // 不存在管理组 if (!isset($groupList[$userData['groupId']])) { // 记录日志 $result['message'] = '没有权限登录(group)'; return $result; } // 填充组信息 $userData['groupData'] = $groupList[$userData['groupId']]; // 获取菜单 $menuData = AdminMenu::getUserMenu($userData); // 保存菜单 $userData['menu'] = $menuData['menu']; // 保存权限 $userData['rightAll'] = $menuData['allRight']; $userData['isInternal'] = intval(IPArea::isInternalIP()); // 获取导航 // 登陆地 if ($userData['isInternal'] == 1) { $userData['loginArea'] = '公司内部'; } else { $userData['loginArea'] = IPArea::getArea(CRequest::getIp()); } // 保存状态 CSession::set('user', $userData); $result = array('status' => true, 'urlPram' => array('c' => 'admin', 'a' => 'index')); // 返回数据 return $result; }
/** * 删除资源 */ public function Action_delRights() { $id = $this->Args('id', 'int'); $status = CModel::factory('adminRightsModel')->delete(array('id' => $id)); if (false == $status) { $errorMessage = CDatabase::getDatabase()->errorInfo(); $errorMessage = isset($errorMessage[2]) ? $errorMessage[2] : ''; } $this->displayAjax($status, $errorMessage); }