vendor/sulu/community-bundle/Controller/RegistrationController.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\CommunityBundle\Controller;
  11. use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. /**
  15.  * Handle registration page.
  16.  */
  17. class RegistrationController extends AbstractController
  18. {
  19.     use SaveMediaTrait {
  20.         getSubscribedServices as getSubscribedServicesOfSaveMediaTrait;
  21.     }
  22.     public const TYPE Configuration::TYPE_REGISTRATION;
  23.     /**
  24.      * Handle registration form.
  25.      */
  26.     public function indexAction(Request $request): Response
  27.     {
  28.         $communityManager $this->getCommunityManager($this->getWebspaceKey());
  29.         // Create Form
  30.         $form $this->createForm(
  31.             $communityManager->getConfigTypeProperty(self::TYPEConfiguration::FORM_TYPE),
  32.             null,
  33.             $communityManager->getConfigTypeProperty(self::TYPEConfiguration::FORM_TYPE_OPTIONS)
  34.         );
  35.         $form->handleRequest($request);
  36.         $success false;
  37.         // Handle Form Success
  38.         if ($form->isSubmitted() && $form->isValid()) {
  39.             // Set Password and Salt
  40.             $user $this->setUserPasswordAndSalt($form->getData(), $form);
  41.             if (!$user->getLocale()) {
  42.                 $user->setLocale($request->getLocale());
  43.             }
  44.             $this->saveMediaFields($form$user$request->getLocale());
  45.             // Register User
  46.             $user $communityManager->register($user);
  47.             // Save User
  48.             $this->saveEntities();
  49.             // Login User
  50.             if ($this->checkAutoLogin(Configuration::TYPE_REGISTRATION)) {
  51.                 $communityManager->login($user$request);
  52.             }
  53.             // Redirect
  54.             $redirectTo $communityManager->getConfigTypeProperty(self::TYPEConfiguration::REDIRECT_TO);
  55.             if ($redirectTo) {
  56.                 return $this->redirect($redirectTo);
  57.             }
  58.             $success true;
  59.         }
  60.         return $this->renderTemplate(
  61.             self::TYPE,
  62.             [
  63.                 'form' => $form,
  64.                 'success' => $success,
  65.             ]
  66.         );
  67.     }
  68.     /**
  69.      * @return array<string|int, string>
  70.      */
  71.     public static function getSubscribedServices(): array
  72.     {
  73.         return \array_merge(parent::getSubscribedServices(), self::getSubscribedServicesOfSaveMediaTrait());
  74.     }
  75. }