entityManager = $entityManager; $this->recordServiceContainer = $recordServiceContainer; $this->user = $user; } public function isApiKeyValid(string $apiKey): bool { $leadCapture = $this->entityManager ->getRDBRepositoryByClass(LeadCaptureEntity::class) ->where([ 'apiKey' => $apiKey, 'isActive' => true, ]) ->findOne(); if ($leadCapture) { return true; } return false; } /** * @throws ForbiddenSilent * @throws NotFound */ public function generateNewApiKeyForEntity(string $id): Entity { $service = $this->recordServiceContainer->get(LeadCaptureEntity::ENTITY_TYPE); $entity = $service->getEntity($id); if (!$entity) { throw new NotFound(); } $entity->set('apiKey', $this->generateApiKey()); $this->entityManager->saveEntity($entity); $service->prepareEntityForOutput($entity); return $entity; } public function generateApiKey(): string { return Util::generateApiKey(); } /** * @return stdClass[] * @throws Forbidden */ public function getSmtpAccountDataList(): array { if (!$this->user->isAdmin()) { throw new Forbidden(); } $dataList = []; $inboundEmailList = $this->entityManager ->getRDBRepositoryByClass(InboundEmail::class) ->where([ 'useSmtp' => true, 'status' => InboundEmail::STATUS_ACTIVE, ['emailAddress!=' => ''], ['emailAddress!=' => null], ]) ->find(); foreach ($inboundEmailList as $inboundEmail) { $item = (object) []; $key = 'inboundEmail:' . $inboundEmail->getId(); $item->key = $key; $item->emailAddress = $inboundEmail->getEmailAddress(); $item->fromName = $inboundEmail->getFromName(); $dataList[] = $item; } return $dataList; } }