/** * 增加新的文章 * * @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; }
/** * 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; }
/** * 编辑用户的资料 * * @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')); }
/** * 修改自己的密码 * * @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 boolean true|false */ public function hasLogin() { $hasLogin = SC::getLoginSession(); return $hasLogin && $this->checkLeftTime(); }
/** * 判断是否已经登录 * * @return boolean true|false */ public function hasLogin() { return SC::getLoginSession(); }
/** * top */ public function top() { $username = SC::getLoginSession()->name; return view('admin.widget.top', compact('username')); }
/** * 检测指定的工作流的指定的步骤是否有权限 * * @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')); }