public function validateIsProfileOwnedByAccount(Account $account, Profile $profile) : self
 {
     if (!$account->getProfiles()->contains($profile)) {
         throw new PermissionsDeniedException("You're not an owner of this profile");
     }
     return $this;
 }
예제 #2
0
 public function format(Account $account, array $frontline)
 {
     $profiles = array_map(function (Profile $profile) {
         return $this->profileFormatter->format($profile);
     }, $account->getProfiles()->toArray());
     return ["api_key" => $account->getAPIKey(), "account" => $account->toJSON(), "profiles" => $profiles, "frontline" => $frontline];
 }
예제 #3
0
 public function __invoke(Account $account)
 {
     $accountId = $account->getId();
     $accountEmail = $account->getEmail();
     $this->accountRepository->deleteAccount($account);
     return ['id' => $accountId, 'email' => $accountEmail, 'entity' => $account];
 }
예제 #4
0
 public function createProfileForAccount(Account $account) : Profile
 {
     if ($account->getProfiles()->count() >= self::MAX_PROFILES_PER_ACCOUNT) {
         throw new MaxProfilesReachedException(sprintf('You can only have %d profiles per account', self::MAX_PROFILES_PER_ACCOUNT));
     }
     $account->getProfiles()->add($profile = new Profile($account));
     $this->profileRepository->createProfile($profile);
     $this->accountService->switchToProfile($account, $profile->getId());
     $this->generateProfileImage($profile->getId());
     $this->backdropService->backdropPreset($profile, $this->backdropPresetFactory, $this->backdropPresetFactory->getListIds()[array_rand($this->backdropPresetFactory->getListIds())]);
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_CREATED, [$profile]);
     return $profile;
 }
예제 #5
0
 public function verifyPassword(Account $account, string $password) : bool
 {
     return password_verify($password, $account->getPassword());
 }
예제 #6
0
 public function auth(Account $account) : Account
 {
     $_SESSION[SessionStrategy::SESSION_API_KEY] = $account->getAPIKey();
     $this->currentAccountService->signInWithAccount($account);
     return $account;
 }
예제 #7
0
 public function equals(Account $compare) : bool
 {
     return $compare->getId() === $this->getId();
 }
예제 #8
0
 public function switchToProfile(Account $account, int $switchToProfileId) : Account
 {
     if (!$account->getProfiles()->filter(function (Profile $profile) use($switchToProfileId) {
         return $profile->getId() === $switchToProfileId;
     })->count()) {
         throw new AccountNotContainsProfileException(sprintf('Profile (ID: %s) is not exists', $switchToProfileId));
     }
     $account->getProfiles()->map(function (Profile $profile) use($switchToProfileId, &$found) {
         $profile->getId() === $switchToProfileId ? $profile->setAsCurrent() : $profile->unsetAsCurrent();
     });
     $this->accountRepository->saveAccount($account);
     array_map(function (Profile $profile) {
         $this->profileRepository->saveProfile($profile);
     }, $account->getProfiles()->toArray());
     return $account;
 }
예제 #9
0
 public function toJSON() : array
 {
     return ['account' => $this->account->toJSON(), 'apps' => ['admin' => $this->appAdmin, 'reports' => $this->appReports, 'feedback' => $this->appFeedback]];
 }