/** * 返回内容区域的菜单 */ protected function getContentMenu() { $this->list = SC::getUserPermissionSession(); foreach ($this->list as $key => $value) { if ($value['display'] == self::DISABLE_NONE) { unset($this->list[$key]); } } $this->menuTree = (array) Tree::genTree($this->list); $son = \App\Services\Admin\Tree::getSonKey(); $mcaName = \App\Services\Admin\MCAManager::MAC_BIND_NAME; $MCA = app()->make($mcaName); foreach ($this->menuTree as $key => $value) { if (isset($value[$son]) and is_array($value[$son])) { foreach ($value[$son] as $skey => $svalue) { if (!$MCA->matchSecondMenu($svalue['module'], $svalue['class'], $svalue['action'])) { continue; } if (isset($svalue[$son]) and is_array($svalue[$son])) { return $svalue[$son]; } } } } return []; }
/** * 增加新的文章 * * @param object $data 文章的信息 * @access public * @return boolean */ public function addContent(ContentSave $data) { if (!$this->contentValidate->add($data)) { $unValidateMsg = $this->contentValidate->getErrorMessage(); return $this->setErrorMsg($unValidateMsg); } $articleObj = new \stdClass(); $articleObj->time = time(); $articleObj->userId = SC::getLoginSession()->id; try { $articleObj->autoId = $this->saveContent($data, $articleObj); $this->saveContentDetail($data, $articleObj); $this->saveArticleTags($articleObj, $data['tags']); $this->saveArticleClassify($articleObj, $data['classify']); $this->saveSeachFullText($articleObj, $data); $this->contentSaveSuccess($articleObj->autoId); $result = true; } catch (Exception $e) { $result = false; } if (!$result) { return $this->setErrorMsg(Lang::get('common.action_error')); } return true; }
/** * 用户登陆验证 * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $isLogin = (new LoginProcess())->getProcess()->hasLogin(); if (empty($isLogin)) { return redirect(route('foundation.login.out')); } SC::setUserCurrentTime(); return $next($request); }
/** * 取回登录所保存的权限信息并生成树形结构 */ protected function generalData() { $this->list = SC::getUserPermissionSession(); foreach ($this->list as $key => $value) { if ($value['display'] == self::DISABLE_NONE) { unset($this->list[$key]); } } $this->menuTree = (array) Tree::genTree($this->list); return $this; }
/** * 开始登录处理,并保存用户的权限信息 * * @param App\Services\Admin\Login\Process $loginProcess 登录核心处理 * @access public */ public function getProc(LoginProcess $loginProcess, Acl $aclObj) { $username = Request::input('username'); $password = Request::input('password'); $callback = Request::input('callback'); if ($error = $loginProcess->getProcess()->validate($username, $password)) { return response()->json(['msg' => $error, 'result' => false])->setCallback($callback); } //开始登录验证 if ($userInfo = $loginProcess->getProcess()->check($username, $password)) { //设置用户的权限 SC::setUserPermissionSession($aclObj->getUserAccessPermission($userInfo)); } $result = $userInfo ? ['msg' => '登录成功', 'result' => true, 'jumpUrl' => R('common', 'foundation.index.index')] : ['msg' => '登录失败', 'result' => false]; return response()->json($result)->setCallback($callback); }
/** * Create a new event instance. * * @return void */ public function __construct($message, $extendsDatas = []) { if (!isset($extendsDatas['userInfo'])) { $extendsDatas['userInfo'] = SC::getLoginSession(); } $userInfo = $extendsDatas['userInfo']; if (isset($userInfo->id)) { $this->userId = $userInfo->id; } if (isset($userInfo->name)) { $this->userName = $userInfo->name; } if (isset($userInfo->realname)) { $this->realName = $userInfo->realname; } $this->message = $message; }
/** * 检测是否有审核的权限 * * @param string $code 调用代码,即检测哪个工作流的 * @param array $status 当前审核状态 * @access public */ public function checkAcl($code, $status = []) { if (!is_array($status)) { return false; } $userInfo = SC::getLoginSession(); //为了避免多次查询的情况,先把它缓存起来,但要注意的系不要重新实例化,widget()方法是不会重新实例化的 if (!isset($this->userWorkflow[$code])) { $this->userWorkflow[$code] = $this->workflowModel->getCurrentUserWorkflow($userInfo->id, $code); } $isCheck = false; foreach ($status as $s) { if ($s == self::DEFAULT_STATUS) { $s = self::DEFAULT_STATUS_REPLACE; } if (in_array($s, $this->userWorkflow[$code])) { $isCheck = true; break; } } return $isCheck; }
/** * 增加新的文章 * * @param string $data * @access public * @return boolean true|false */ public function addContent(\App\Services\Admin\Content\Param\ContentSave $data) { if (!$this->contentValidate->add($data)) { return $this->setErrorMsg($this->contentValidate->getErrorMessage()); } $object = new \stdClass(); $object->time = time(); $object->userId = SC::getLoginSession()->id; try { $result = \DB::transaction(function () use($data, $object) { $object->contentAutoId = $this->saveContent($data, $object); $this->saveContentDetail($data, $object); $this->saveArticleTags($object, $data['tags']); $this->saveArticleClassify($object, $data['classify']); $this->saveSeachFullText($object, $data); return true; }); } catch (\Exception $e) { $result = false; } return !$result ? $this->setErrorMsg(Lang::get('common.action_error')) : true; }
/** * 修改自己的密码 * * @param object $params * @return true|false */ public function modifyPassword(UserModifyPassword $params) { if (!$this->userValidate->password($params)) { return $this->setErrorMsg($this->userValidate->getErrorMessage()); } $userInfo = SC::getLoginSession(); if ($userInfo->password != md5($params->oldPassword)) { return $this->setErrorMsg(Lang::get('user.old_password_wrong')); } $updateData = ['password' => md5($params->newPassword)]; if ($this->userModel->editUser($updateData, $userInfo->id) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * 是否系统的创始人帐号 * * @return boolean true|false */ public function isSuperSystemManager($userObj = false) { if (!$userObj) { $userObj = SC::getLoginSession(); } if ($userObj->name == self::ADMIN_NAME or $userObj->id == self::ADMIN_ID) { return true; } return false; }
/** * 登录退出 * * @return void */ public function logout() { return SC::delLoginSession(); }
/** * top */ public function top() { $username = SC::getLoginSession()->name; return view('admin.widget.top', compact('username')); }
/** * 为权限赋予页面准备ztree插件需要的数据 * * @return array */ public function prepareUserPermissionIds() { $list = SC::getUserPermissionSession(); $all = []; foreach ($list as $key => $value) { $all[] = $value['id']; } return $all; }
/** * 检测指定的工作流的指定的步骤是否有权限 * * @return true|false */ public function checkStepAcl($workflowCode, $workflowStepCode) { if (!is_string($workflowCode) or !is_string($workflowStepCode)) { return false; } $key = md5($workflowCode . $workflowStepCode); $userInfo = SC::getLoginSession(); if (!isset($this->userWorkflow[$key])) { $this->userWorkflow[$key] = $this->workflowModel->getCurrentUserWorkflowStep($userInfo->id, $workflowCode, $workflowStepCode); } return !empty($this->userWorkflow[$key]); }
/** * 修改自己的密码 * * @param object $params * @return true|false */ public function modifyPassword(\App\Services\Admin\User\Param\UserModifyPassword $params) { if (!$this->userValidate->password($params)) { return $this->setErrorMsg($this->userValidate->getErrorMessage()); } $loginProcess = new \App\Services\Admin\Login\Process(); $userInfo = \App\Services\Admin\SC::getLoginSession(); if ($userInfo->password != md5($params->oldPassword)) { return $this->setErrorMsg(Lang::get('user.old_password_wrong')); } $updateData = ['password' => md5($params->newPassword)]; if (app('model.admin.user')->editUser($updateData, $userInfo->id) !== false) { return true; } return $this->setErrorMsg(Lang::get('common.action_error')); }
/** * return user permission */ private function getUserPermission() { if (!$this->userPermission) { $this->userPermission = SC::getUserPermissionSession(); } return $this->userPermission; }
/** * 编辑用户的资料 * * @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')); }
/** * 对用户组进行权限设置 * * @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')); }