getQueryParam('id'); if (empty($userId)) { throw new Error(); } if ( !$this->user->isAdmin() && $this->user->getId() !== $userId ) { throw new Forbidden(); } $user = $this->entityManager->getEntityById(\Espo\Entities\User::ENTITY_TYPE, $userId); if (empty($user)) { throw new NotFound(); } return $this->aclManager->getMapData($user); } /** * @throws BadRequest * @throws Forbidden * @throws Error * @throws NotFound */ public function postActionChangeOwnPassword(Request $request): bool { $data = $request->getParsedBody(); $password = $data->password ?? null; $currentPassword = $data->currentPassword ?? null; if ( !is_string($password) || !is_string($currentPassword) ) { throw new BadRequest(); } $this->getPasswordService()->changePasswordWithCheck($this->user->getId(), $password, $currentPassword); return true; } /** * @throws BadRequest * @throws Forbidden * @throws Error * @throws NotFound */ public function postActionChangePasswordByRequest(Request $request): stdClass { $data = $request->getParsedBody(); if (empty($data->requestId) || empty($data->password)) { throw new BadRequest(); } $url = $this->getPasswordService()->changePasswordByRecovery($data->requestId, $data->password); return (object) [ 'url' => $url, ]; } /** * @throws BadRequest * @throws Forbidden */ public function postActionPasswordChangeRequest(Request $request): bool { $data = $request->getParsedBody(); $userName = $data->userName ?? null; $emailAddress = $data->emailAddress ?? null; $url = $data->url ?? null; if (!$userName || !$emailAddress) { throw new BadRequest(); } $this->injectableFactory ->create(RecoveryService::class) ->request($emailAddress, $userName, $url); return true; } /** * @throws BadRequest * @throws Forbidden * @throws NotFound */ public function postActionGenerateNewApiKey(Request $request): stdClass { $data = $request->getParsedBody(); if (empty($data->id)) { throw new BadRequest(); } if (!$this->user->isAdmin()) { throw new Forbidden(); } return $this->injectableFactory ->create(ApiService::class) ->generateNewApiKey($data->id) ->getValueMap(); } /** * @throws BadRequest * @throws Forbidden * @throws Error * @throws SendingError * @throws NotFound */ public function postActionGenerateNewPassword(Request $request): bool { $data = $request->getParsedBody(); if (empty($data->id)) { throw new BadRequest(); } if (!$this->user->isAdmin()) { throw new Forbidden(); } $this->getPasswordService()->generateAndSendNewPasswordForUser($data->id); return true; } /** * @throws BadRequest * @throws Forbidden * @throws NotFound * @throws Error */ public function postActionSendPasswordChangeLink(Request $request): bool { if (!$this->user->isAdmin()) { throw new Forbidden(); } $id = $request->getParsedBody()->id ?? null; if (!$id) { throw new BadRequest(); } $this->getPasswordService()->createAndSendPasswordRecovery($id); return true; } public function postActionCreateLink(Request $request): bool { if (!$this->user->isAdmin()) { throw new Forbidden(); } return parent::postActionCreateLink($request); } public function deleteActionRemoveLink(Request $request): bool { if (!$this->user->isAdmin()) { throw new Forbidden(); } return parent::deleteActionRemoveLink($request); } protected function fetchSearchParamsFromRequest(Request $request): SearchParams { $searchParams = parent::fetchSearchParamsFromRequest($request); $userType = $request->getQueryParam('userType'); if (!$userType) { return $searchParams; } return $searchParams->withWhereAdded( WhereItem::fromRaw([ 'type' => 'isOfType', 'attribute' => 'id', 'value' => $userType, ]) ); } private function getPasswordService(): PasswordService { return $this->injectableFactory->create(PasswordService::class); } }