/** * 编辑用户的资料 * * @access public */ public function edit(User $userModel, Acl $acl, Group $groupModel) { if (Request::method() == 'POST') { return $this->updateUserInfo(); } Session::flashInput(['http_referer' => Session::getOldInput('http_referer')]); $id = Request::input('id'); $userId = url_param_decode($id); if (!$userId or !is_numeric($userId)) { return Js::error(Lang::get('common.illegal_operation'), true); } $userInfo = $userModel->getOneUserById($userId); if (empty($userInfo)) { return Js::error(Lang::get('user.user_not_found'), true); } if (!$acl->checkGroupLevelPermission($userId, Acl::GROUP_LEVEL_TYPE_USER)) { return Js::error(Lang::get('common.account_level_deny'), true); } $groupInfo = $groupModel->getOneGroupById(SC::getLoginSession()->group_id); if ($acl->isSuperSystemManager()) { $groupInfo['level'] = 0; } $groupList = $groupModel->getGroupLevelLessThenCurrentUser($groupInfo['level']); $formUrl = route('foundation.user.edit'); return view('admin.user.add', compact('userInfo', 'formUrl', 'id', 'groupList')); }
/** * 验证ID * * @param array $ids * @return array IDS */ public function deleteIds(array $ids) { foreach ($ids as $key => $value) { if (!($ids[$key] = url_param_decode($value))) { return false; } } return array_map('intval', $ids); }
/** * 编辑用户组 * * @access public */ public function edit() { if (Request::method() == 'POST') { return $this->updateDatasToDatabase(); } Session::flashInput(['http_referer' => Session::getOldInput('http_referer')]); $id = Request::input('id'); $groupId = url_param_decode($id); if (!$groupId or !is_numeric($groupId)) { return Js::error(Lang::get('common.illegal_operation')); } $groupInfo = app('model.admin.group')->getOneGroupById($groupId); if (empty($groupInfo)) { return Js::error(Lang::get('group.group_not_found')); } if (!app('admin.acl')->checkGroupLevelPermission($groupId, Acl::GROUP_LEVEL_TYPE_GROUP)) { return Js::error(Lang::get('common.account_level_deny'), true); } $formUrl = R('common', 'foundation.group.edit'); return view('admin.group.add', compact('groupInfo', 'formUrl', 'id')); }
/** * 编辑用户 * * @param object $data * @access public * @return boolean true|false */ public function editUser(UserSave $data) { $id = intval(url_param_decode($data->id)); unset($data->id); if (!$id) { return $this->setErrorMsg(Lang::get('common.illegal_operation')); } if (!$this->userValidate->edit($data)) { return $this->setErrorMsg($this->userValidate->getErrorMessage()); } if (!empty($data->password)) { $data->setPassword(md5($data->password)); } else { unset($data->password); } if (!$this->acl->checkGroupLevelPermission($id, Acl::GROUP_LEVEL_TYPE_USER)) { return $this->setErrorMsg(Lang::get('common.account_level_deny')); } if ($this->userModel->editUser($data->toArray(), $id) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * 对用户组进行权限设置 * * @access public */ public function group(GroupModel $groupModel, Acl $acl, AclProcess $process) { if (Request::method() == 'POST') { return $this->saveGroupPermission(); } $id = url_param_decode(Request::input('id')); if (!$id or !is_numeric($id)) { return Js::error(Lang::get('common.illegal_operation'), true); } $info = $groupModel->getOneGroupById(intval($id)); if (empty($info)) { return Js::error(Lang::get('common.illegal_operation'), true); } if (!$acl->checkGroupLevelPermission($id, Acl::GROUP_LEVEL_TYPE_GROUP)) { return Js::error(Lang::get('common.account_level_deny'), true); } $zTree = $process->prepareDataForZtree($process->getGroupAccessPermissionIds($id)); $all = $process->prepareUserPermissionIds(); $router = 'group'; return view('admin.acl.setpermission', compact('zTree', 'id', 'info', 'router', 'all')); }
/** * 编辑用户组 * * @param object $data * @return boolean true|false * @access public */ public function editGroup(GroupSave $data) { if (!isset($data->id)) { return $this->setErrorMsg(Lang::get('common.action_error')); } $id = intval(url_param_decode($data->id)); unset($data->id); if (!$id) { return $this->setErrorMsg(Lang::get('common.illegal_operation')); } if (!$this->groupValidate->edit($data)) { return $this->setErrorMsg($this->groupValidate->getErrorMessage()); } if (!$this->acl->checkGroupLevelPermission($data->level, Acl::GROUP_LEVEL_TYPE_LEVEL)) { return $this->setErrorMsg(Lang::get('common.account_level_deny')); } if ($this->groupModel->editGroup($data->toArray(), $id) === false) { return $this->setErrorMsg(Lang::get('common.action_error')); } return true; }
/** * 编辑权限菜单 * * @param string $data * @access public * @return boolean true|false */ public function editAcl(\App\Services\Admin\Acl\Param\AclSave $data) { $id = intval(url_param_decode($data->id)); unset($data->id); if (!$id) { return $this->setErrorMsg(Lang::get('common.illegal_operation')); } if (!$this->aclValidate->edit($data)) { return $this->setErrorMsg($this->aclValidate->getErrorMessage()); } if ($this->permissionModel->checkIfIsExists($data->module, $data->class, $data->action, false, $id)) { return $this->setErrorMsg(Lang::get('acl.acl_exists')); } $info = $this->permissionModel->getOnePermissionById(intval($data->pid)); $data = $data->toArray(); $data['level'] = $info['level'] + 1; if ($this->permissionModel->editPermission($data, intval($id)) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * 编辑用户组 * * @param object $data * @access public * @return boolean true|false */ public function editGroup(\App\Services\Admin\Group\Param\GroupSave $data) { if (!isset($data->id)) { return $this->setErrorMsg(Lang::get('common.action_error')); } $id = intval(url_param_decode($data->id)); unset($data->id); if (!$id) { return $this->setErrorMsg(Lang::get('common.illegal_operation')); } if (!$this->groupValidate->edit($data)) { return $this->setErrorMsg($this->groupValidate->getErrorMessage()); } //检查当前用户的权限是否能增加这个用户 if (!app('admin.acl')->checkGroupLevelPermission($data->level, Acl::GROUP_LEVEL_TYPE_LEVEL)) { return $this->setErrorMsg(Lang::get('common.account_level_deny')); } if (app('model.admin.group')->editGroup($data->toArray(), $id) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * 对用户组进行权限设置 * * @access public */ public function group() { if (Request::method() == 'POST') { return $this->saveGroupPermissionToDatabase(); } $id = url_param_decode(Request::input('id')); if (!$id or !is_numeric($id)) { return Js::error(Lang::get('common.illegal_operation'), true); } $info = (new GroupModel())->getOneGroupById(intval($id)); if (empty($info)) { return Js::error(Lang::get('common.illegal_operation'), true); } if (!(new Acl())->checkGroupLevelPermission($id, Acl::GROUP_LEVEL_TYPE_GROUP)) { return Js::error(Lang::get('common.account_level_deny'), true); } //取回用户组所拥有的权限列表 $list = (array) SC::getUserPermissionSession(); //当前所要编辑的用户组的权限,用于标识是否已经勾选 $groupAcl = (new AccessModel())->getGroupAccessPermission(intval($id)); $hasPermissions = array(); foreach ($groupAcl as $key => $value) { $hasPermissions[] = $value['permission_id']; } //为ztree做数据准备 $zTree = []; $all = []; foreach ($list as $key => $value) { $arr = ['id' => $value['id'], 'pId' => $value['pid'], 'name' => $value['name'], 'open' => true]; if (in_array($value['id'], $hasPermissions)) { $arr['checked'] = true; } $zTree[] = $arr; $all[] = $value['id']; } $router = 'group'; return view('admin.acl.setpermission', compact('zTree', 'id', 'info', 'router', 'all')); }
/** * 编辑用户 * * @param object $data * @access public * @return boolean true|false */ public function editUser(\App\Services\Admin\User\Param\UserSave $data) { if (!isset($data->id)) { return $this->setErrorMsg(Lang::get('common.action_error')); } $id = intval(url_param_decode($data->id)); unset($data->id); if (!$id) { return $this->setErrorMsg(Lang::get('common.illegal_operation')); } if (!$this->userValidate->edit($data)) { return $this->setErrorMsg($this->userValidate->getErrorMessage()); } if (!empty($data->password)) { $data->setPassword(md5($data->password)); } else { unset($data->password); } //检查当前用户的权限是否能增加这个用户 if (!app('admin.acl')->checkGroupLevelPermission($id, Acl::GROUP_LEVEL_TYPE_USER)) { return $this->setErrorMsg(Lang::get('common.account_level_deny')); } if (app('model.admin.user')->editUser($data->toArray(), $id) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * 编辑权限菜单 * * @param object $data * @return boolean true|false * @access public */ public function editAcl(AclSave $data) { $id = intval(url_param_decode($data->id)); unset($data->id); if (!$id) { return $this->setErrorMsg(Lang::get('common.illegal_operation')); } if (!$this->aclValidate->edit($data)) { return $this->setErrorMsg($this->aclValidate->getErrorMessage()); } if ($this->permissionModel->checkIfIsExists($data->module, $data->class, $data->action, false, $id)) { return $this->setErrorMsg(Lang::get('acl.acl_exists')); } $data = $data->toArray(); if ($this->permissionModel->editPermission($data, intval($id)) === false) { return $this->setErrorMsg(Lang::get('common.action_error')); } return true; }