Skip to content

Commit

Permalink
finalized social-media provider and token-repository
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Aug 16, 2018
1 parent 7e2999a commit 85fbac2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Entity/UserAccessTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@

<!-- social-media -->
<service id="sulu_community.social_media.oauth_provider" class="Sulu\Bundle\CommunityBundle\SocialMedia\SocialMediaUserProvider">
<argument type="service" id="sulu_community.community_manager.registry"/>
<argument type="service" id="request_stack"/>
<argument type="service" id="doctrine"/>
</service>
</services>
Expand Down
28 changes: 20 additions & 8 deletions SocialMedia/SocialMediaUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -41,20 +52,18 @@ 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 = [],
$managerName = null
) {
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());
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 85fbac2

Please sign in to comment.