Exemplo n.º 1
0
 /**
  * Constructor.
  *
  * @param string                 $guid
  * @param string                 $providerName
  * @param AccessToken            $accessToken
  * @param ResourceOwnerInterface $resourceOwner
  */
 public function __construct($guid, $providerName, AccessToken $accessToken, ResourceOwnerInterface $resourceOwner)
 {
     if (Uuid::isValid($guid) === false) {
         throw new \RuntimeException('Tried to create Transition object with an invalid GUID.');
     }
     $this->guid = $guid;
     $this->accessToken = $accessToken;
     $this->resourceOwner = $resourceOwner;
     $providerEntity = new Entity\Provider();
     $providerEntity->setProvider($providerName);
     $providerEntity->setRefreshToken($accessToken->getRefreshToken());
     $providerEntity->setResourceOwnerId($resourceOwner->getId());
     $providerEntity->setResourceOwner($resourceOwner);
     $this->providerEntity = $providerEntity;
 }
Exemplo n.º 2
0
 /**
  * Add a member.
  *
  * @param Application $app
  * @param Request     $request
  *
  * @return Response
  */
 public function userAdd(Application $app, Request $request)
 {
     $builder = $app['members.forms.manager']->getFormProfileEdit($request, true, null);
     $form = $builder->getForm(Form\MembersForms::FORM_PROFILE_EDIT);
     // Handle the form request data
     if ($form->isValid()) {
         /** @var Form\Entity\Profile $entity */
         $entity = $builder->getEntity(Form\MembersForms::FORM_PROFILE_EDIT);
         // Create and store the account entity
         $account = new Storage\Entity\Account();
         $account->setGuid($entity->getGuid());
         $account->setDisplayname($entity->getDisplayname());
         $account->setEmail($entity->getEmail());
         $account->setRoles([]);
         $account->setEnabled(true);
         $app['members.records']->saveAccount($account);
         // Save the password to a meta record
         $oauth = new Storage\Entity\Oauth();
         $oauth->setGuid($account->getGuid());
         $oauth->setResourceOwnerId($account->getGuid());
         $oauth->setEnabled(true);
         $app['members.records']->saveOauth($oauth);
         // Create a local provider entry
         $provider = new Storage\Entity\Provider();
         $provider->setGuid($account->getGuid());
         $provider->setProvider('local');
         $provider->setResourceOwnerId($account->getGuid());
         $provider->setLastupdate(Carbon::now());
         $app['members.records']->saveProvider($provider);
         return new RedirectResponse($app['url_generator']->generate('membersAdmin'));
     }
     $html = $app['members.forms.manager']->renderForms($builder, $app['twig'], '@MembersAdmin/profile_add.twig');
     return new Response(new \Twig_Markup($html, 'UTF-8'));
 }
Exemplo n.º 3
0
 /**
  * Create and store a new provider.
  *
  * @param string $guid
  * @param string $providerName
  * @param string $resourceOwnerId
  *
  * @return Entity\Provider
  */
 public function createProviderEntity($guid, $providerName, $resourceOwnerId)
 {
     $provider = new Entity\Provider();
     $provider->setGuid($guid);
     $provider->setProvider($providerName);
     $provider->setResourceOwnerId($resourceOwnerId);
     $provider->setLastupdate(Carbon::now());
     $this->getProviderRepository()->save($provider);
     return $provider;
 }
Exemplo n.º 4
0
 /**
  * .
  *
  * @param string                 $providerName
  * @param AccessToken            $accessToken
  * @param ResourceOwnerInterface $resourceOwner
  */
 protected function setSessionNewProvider($providerName, AccessToken $accessToken, ResourceOwnerInterface $resourceOwner)
 {
     if ($this->session->hasAuthorisation()) {
         // Member is already in possession of another login, and the provider does NOT exist
         $this->createProviderTransition($accessToken, $resourceOwner);
         return;
     }
     $account = $this->records->getAccountByEmail($resourceOwner->getEmail());
     if ($account === false) {
         $account = $this->records->createAccount($resourceOwner->getName(), $resourceOwner->getEmail(), $this->config->getRolesRegister());
     }
     $providerEntity = new Entity\Provider();
     $providerEntity->setGuid($account->getGuid());
     $providerEntity->setProvider($providerName);
     $providerEntity->setResourceOwner($resourceOwner);
     $providerEntity->setResourceOwnerId($resourceOwner->getId());
     $providerEntity->setLastupdate(Carbon::now());
     $this->records->saveProvider($providerEntity);
     $this->session->addAccessToken($providerName, $accessToken)->createAuthorisation($providerEntity->getGuid());
     $this->providerEntity = $providerEntity;
 }