Exemplo n.º 1
0
 /**
  * Create and store the account record.
  *
  * @param string $displayName
  * @param string $emailAddress
  * @param array  $roles
  *
  * @return Entity\Account|false
  */
 public function createAccount($displayName, $emailAddress, array $roles)
 {
     $account = new Entity\Account();
     $account->setDisplayname($displayName);
     $account->setEmail($emailAddress);
     $account->setRoles($roles);
     $account->setEnabled(true);
     $account->setVerified(false);
     return $this->getAccountRepository()->save($account) ? $account : false;
 }
Exemplo n.º 2
0
 /**
  * Save a user view/edit form data.
  *
  * @param Storage\Entity\Account $account
  * @param Form                   $form
  *
  * @return FormEntityHandler
  */
 public function saveProfileForm(Storage\Entity\Account $account, Form $form)
 {
     $guid = $account->getId();
     if ($guid === null) {
         throw new \RuntimeException('GUID not set.');
     }
     $account->setDisplayname($form->get('displayname')->getData());
     $account->setEmail($form->get('email')->getData());
     // Dispatch the account profile pre-save event
     $event = new MembersProfileEvent($account);
     $this->eventDispatcher->dispatch(MembersEvents::MEMBER_PROFILE_PRE_SAVE, $event);
     $this->records->saveAccount($account);
     $password = $form->get('password')->getData();
     if ($password !== null) {
         $oauth = $this->getOauth($guid);
         if ($oauth === false) {
             $oauth = $this->createLocalOauthAccount($guid, $password);
             $this->createLocalProviderEntity($guid);
         }
         $oauth->setPassword($password);
         $this->records->saveOauth($oauth);
     }
     // Save any defined meta fields
     foreach ($event->getMetaEntityNames() as $metaField) {
         $metaEntity = $this->records->getAccountMeta($guid, $metaField);
         if ($metaEntity === false) {
             $metaEntity = new Storage\Entity\AccountMeta();
         }
         $metaEntity->setGuid($guid);
         $metaEntity->setMeta($metaField);
         $metaEntity->setValue($form->get($metaField)->getData());
         $this->records->saveAccountMeta($metaEntity);
         $event->addMetaEntity($metaEntity);
     }
     // Dispatch the account profile post-save event
     $this->eventDispatcher->dispatch(MembersEvents::MEMBER_PROFILE_POST_SAVE, $event);
     return $this;
 }
Exemplo n.º 3
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'));
 }