diff --git a/Entity/UserAccessTokenRepository.php b/Entity/UserAccessTokenRepository.php index 6608ce75..f1444247 100644 --- a/Entity/UserAccessTokenRepository.php +++ b/Entity/UserAccessTokenRepository.php @@ -19,8 +19,10 @@ class UserAccessTokenRepository extends EntityRepository public function create(UserInterface $user, string $service, string $identifier): UserAccessToken { $class = $this->getClassName(); + $accessToken = new $class($user, $service, $identifier); + $this->getEntityManager()->persist($accessToken); - return new $class($user, $service, $identifier); + return $accessToken; } public function findByIdentifier(string $service, string $identifier): ?UserAccessToken diff --git a/Resources/config/services.xml b/Resources/config/services.xml index bbbb530f..85a6aeb6 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -150,6 +150,8 @@ + + diff --git a/SocialMedia/SocialMediaUserProvider.php b/SocialMedia/SocialMediaUserProvider.php index ab8c1586..8bc476f8 100644 --- a/SocialMedia/SocialMediaUserProvider.php +++ b/SocialMedia/SocialMediaUserProvider.php @@ -17,15 +17,26 @@ use HWI\Bundle\OAuthBundle\Security\Core\User\EntityUserProvider; use Sulu\Bundle\CommunityBundle\Entity\UserAccessToken; use Sulu\Bundle\CommunityBundle\Entity\UserAccessTokenRepository; -use Sulu\Bundle\CommunityBundle\Manager\CommunityManagerInterface; +use Sulu\Bundle\CommunityBundle\Manager\CommunityManagerRegistryInterface; use Sulu\Bundle\ContactBundle\Entity\ContactInterface; use Sulu\Bundle\ContactBundle\Entity\ContactRepositoryInterface; use Sulu\Component\Security\Authentication\UserInterface as SuluUserInterface; use Sulu\Component\Security\Authentication\UserRepositoryInterface; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\User\UserInterface; class SocialMediaUserProvider extends EntityUserProvider implements AccountConnectorInterface { + /** + * @var CommunityManagerRegistryInterface + */ + private $communityManagerRegistry; + + /** + * @var RequestStack + */ + private $requestStack; + /** * @var UserAccessTokenRepository */ @@ -41,13 +52,9 @@ class SocialMediaUserProvider extends EntityUserProvider implements AccountConne */ private $contactRepository; - /** - * @var CommunityManagerInterface - */ - private $communityManager; - public function __construct( - CommunityManagerInterface $community, + CommunityManagerRegistryInterface $communityManagerRegistry, + RequestStack $requestStack, ManagerRegistry $registry, $class = SuluUserInterface::class, array $properties = [], @@ -55,6 +62,8 @@ public function __construct( ) { parent::__construct($registry, $class, $properties, $managerName); + $this->communityManagerRegistry = $communityManagerRegistry; + $this->requestStack = $requestStack; $this->userAccessTokenRepository = $this->em->getRepository(UserAccessToken::class); $this->userRepository = $this->em->getRepository($this->em->getClassMetadata(SuluUserInterface::class)->getName()); $this->contactRepository = $this->em->getRepository($this->em->getClassMetadata(ContactInterface::class)->getName()); @@ -121,7 +130,10 @@ public function loadUserByOAuthUserResponse(UserResponseInterface $response) $user->setSalt(uniqid()); $user->setPassword($username); - $this->communityManager->register($user); + $request = $this->requestStack->getCurrentRequest(); + $webspaceKey = $request->attributes->get('_sulu')->getAttribute('webspace')->getKey(); + + $this->communityManagerRegistry->get($webspaceKey)->register($user); $user->setEnabled(true); $this->em->flush();