public function format(Community $community)
 {
     $isOwn = false;
     if ($this->currentAccountService->isAvailable()) {
         $isOwn = $this->currentAccountService->getCurrentAccount()->equals($community->getOwner());
     }
     return ['community' => $community->toJSON(), 'collections' => $this->formatCollections($community->getCollections()), 'is_own' => $isOwn];
 }
示例#2
0
 public function createCommunity(CreateCommunityParameters $parameters) : Community
 {
     $owner = $this->currentAccountService->getCurrentAccount();
     $entity = new Community($owner, $parameters->getTitle(), $parameters->getDescription(), $parameters->hasThemeId() ? $this->themeRepository->getThemeById($parameters->getThemeId()) : null);
     $this->communityRepository->createCommunity($entity);
     $strategy = new CommunityImageStrategy($entity, $this->imageFileSystem, $this->wwwImageDir);
     $this->avatarService->generateImage($strategy);
     $this->backdropService->backdropPreset($entity, $this->backdropPresetFactory, $this->backdropPresetFactory->getListIds()[array_rand($this->backdropPresetFactory->getListIds())]);
     $this->communityRepository->saveCommunity($entity);
     $this->getEventEmitter()->emit(self::EVENT_COMMUNITY_CREATED, [$entity]);
     return $entity;
 }
示例#3
0
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $isURLProtected = strpos($request->getUri()->getPath(), "/protected/") === 0;
     try {
         $this->currentAccountService->signInWithStrategies([new HeaderStrategy($request), new JSONBodyStrategy($request), new SessionStrategy($request)]);
     } catch (NotAuthenticatedException $e) {
         if ($isURLProtected) {
             $responseBuilder = new CASSResponseBuilder($response);
             return $responseBuilder->setStatusNotAllowed()->setError($e)->build();
         }
     }
     return $out($request, $response);
 }
示例#4
0
 public function auth(Account $account) : Account
 {
     $_SESSION[SessionStrategy::SESSION_API_KEY] = $account->getAPIKey();
     $this->currentAccountService->signInWithAccount($account);
     return $account;
 }
 public function __invoke(Request $request, Response $response, callable $out = null)
 {
     $account = $this->currentAccountService->getCurrentAccount();
     $access = $this->accountAppAccessService->hasAppAccess($account) ? $this->accountAppAccessService->getAppAccess($account) : $this->accountAppAccessService->getDefaultAppAccess($account);
     return (new CASSResponseBuilder($response))->setStatusSuccess()->setJson(['access' => $access->toJSON()])->build();
 }
示例#6
0
 public function specifyProfile(int $profileId)
 {
     $this->currentProfile = $this->currentAccountService->getCurrentAccount()->getProfileWithId($profileId);
 }
 public function format(Profile $profile) : array
 {
     return ['profile' => $profile->toJSON(), 'collections' => $this->formatCollections($profile->getCollections()), 'bookmarks' => array_map(function (ProfileCommunityEQ $eq) {
         return $eq->toJSON();
     }, $this->communityBookmarksService->getBookmarksOfProfile($profile->getId())), 'is_own' => $this->currentAccountService->isAvailable() ? $this->currentAccountService->getCurrentAccount()->getProfiles()->contains($profile) : false];
 }