/** * @param TokenInterface $foreignAccountToken * @param AbstractClientToken $possibleOAuthTokenAuthenticatedWithoutParty */ public function setPartyOfAuthenticatedTokenAndAttachToAccountFor(TokenInterface $foreignAccountToken, AbstractClientToken $possibleOAuthTokenAuthenticatedWithoutParty) { $oauthAccount = $possibleOAuthTokenAuthenticatedWithoutParty->getAccount(); // TODO: this must be properly specifiable (the Roles to add) #$oauthAccount->setRoles(); $this->partyService->assignAccountToParty($oauthAccount, $this->partyService->getAssignedPartyOfAccount($foreignAccountToken)); $this->accountRepository->update($oauthAccount); }
/** * @param AbstractClientToken $token * @throws InvalidPartyDataException */ public function createPartyAndAttachToAccountFor(AbstractClientToken $token) { $userData = $this->authenticationServicesUserData[(string) $token]; $party = new Person(); $party->setName(new PersonName('', $userData['first_name'], '', $userData['last_name'])); // Todo: this is not covered by the Person implementation, we should have a solution for that #$party->setBirthDate(\DateTime::createFromFormat('!m/d/Y', $userData['birthday'], new \DateTimeZone('UTC'))); #$party->setGender(substr($userData['gender'], 0, 1)); $electronicAddress = new ElectronicAddress(); $electronicAddress->setType(ElectronicAddress::TYPE_EMAIL); $electronicAddress->setIdentifier($userData['email']); $party->addElectronicAddress($electronicAddress); $partyValidator = $this->validatorResolver->getBaseValidatorConjunction('TYPO3\\Party\\Domain\\Model\\Person'); $validationResult = $partyValidator->validate($party); if ($validationResult->hasErrors()) { throw new InvalidPartyDataException('The created party does not satisfy the requirements', 1384266207); } $account = $token->getAccount(); $account->setParty($party); // TODO: this must be properly specifiable (the Roles to add) #$account->setRoles(); $this->accountRepository->update($account); $this->partyRepository->add($party); }