Exemple #1
0
 public function signInOauth2(RegistrationRequest $registrationRequest)
 {
     if (!$this->accountService->hasAccountWithEmail($registrationRequest->getEmail())) {
         $this->accountService->createOAuth2Account($registrationRequest);
     }
     $oauth2Account = $this->accountService->findOAuthAccount($registrationRequest->getProvider(), $registrationRequest->getProviderAccountId());
     return $this->auth($oauth2Account->getAccount());
 }
Exemple #2
0
 public function validate(SignUpParameters $parameters)
 {
     $hasSameAccount = $this->accountService->hasAccountWithEmail($parameters->getEmail());
     $isValid = !$hasSameAccount;
     if (!$isValid) {
         throw new DuplicateAccountException(sprintf('%s already in use.', $parameters->getEmail()));
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $accountId = $input->getArgument('id');
     if (!is_numeric($accountId)) {
         throw new \InvalidArgumentException('Invalid id');
     }
     $this->accountService->deleteAccount($accountId);
 }
Exemple #4
0
 private function createAccountFromJSON(array $json) : Account
 {
     if ($this->accountService->hasAccountWithEmail($json['email'])) {
         return $this->accountService->getByEmail($json['email']);
     } else {
         $account = $this->accountService->createAccount($json['email'], GenerateRandomString::gen(12));
         $profile = $account->getCurrentProfile();
         $profile->setGender(Gender::createFromIntCode((int) $json['gender']));
         $parameters = new EditPersonalParameters('fl', false, $json['username'] ?? '', $json['surname'] ?? '', $json['patronymic'] ?? '', $json['nickname'] ?? '');
         $this->profileService->updatePersonalData($profile->getId(), $parameters);
         $this->profileService->setInterestingInThemes($profile->getId(), $json['interests']);
         if ($json['birthday']) {
             $this->profileService->setBirthday($profile->getId(), \DateTime::createFromFormat('Y-m-d', $json['birthday']));
         }
         $avatarPath = sprintf("%s/%s", self::AVATAR_DIR, $json['avatar']);
         if (file_exists($avatarPath)) {
             list($width, $height) = getimagesize($avatarPath);
             if (!is_null($width) && !is_null($height)) {
                 $size = min($width, $height);
                 $parameters = new UploadImageParameters($avatarPath, new Point(0, 0), new Point($size, $size));
                 $this->profileService->uploadImage($profile->getId(), $parameters);
             }
         }
         return $account;
     }
 }
Exemple #5
0
 public function deleteProfile(int $profileId) : Profile
 {
     $profile = $this->getProfileById($profileId);
     $account = $profile->getAccount();
     if ($account->getProfiles()->count() === 1) {
         throw new LastProfileException('This is your last profile. Sorry you need at least one profile per account.');
     }
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_DELETE, [$profile]);
     $this->profileRepository->deleteProfile($profile);
     $account->getProfiles()->removeElement($profile);
     if ($profile->isCurrent()) {
         $firstProfile = $account->getProfiles()->first();
         /** @var Profile $firstProfile */
         $this->accountService->switchToProfile($account, $firstProfile->getId());
     }
     $this->getEventEmitter()->emit(self::EVENT_PROFILE_DELETED, [$profile]);
     return $account->getCurrentProfile();
 }