From cf8dd4ddaace7c7a6c0a90667e233719408222ee Mon Sep 17 00:00:00 2001 From: Jordi Sala Date: Sat, 25 Mar 2017 20:20:47 +0100 Subject: [PATCH] Remove FOSUser Controllers --- .../ChangePasswordFOSUser2Controller.php | 87 ---------- Controller/ProfileFOSUser2Controller.php | 149 ------------------ Controller/RegistrationFOSUser2Controller.php | 18 --- Controller/ResettingFOSUser2Controller.php | 21 --- Controller/SecurityFOSUser2Controller.php | 41 ----- .../routing/sonata_change_password_2.xml | 9 -- Resources/config/routing/sonata_profile_2.xml | 21 --- .../config/routing/sonata_registration_2.xml | 27 ---- .../config/routing/sonata_resetting_2.xml | 27 ---- .../config/routing/sonata_security_2.xml | 21 --- 10 files changed, 421 deletions(-) delete mode 100644 Controller/ChangePasswordFOSUser2Controller.php delete mode 100644 Controller/ProfileFOSUser2Controller.php delete mode 100644 Controller/RegistrationFOSUser2Controller.php delete mode 100644 Controller/ResettingFOSUser2Controller.php delete mode 100644 Controller/SecurityFOSUser2Controller.php delete mode 100644 Resources/config/routing/sonata_change_password_2.xml delete mode 100644 Resources/config/routing/sonata_profile_2.xml delete mode 100644 Resources/config/routing/sonata_registration_2.xml delete mode 100644 Resources/config/routing/sonata_resetting_2.xml delete mode 100644 Resources/config/routing/sonata_security_2.xml diff --git a/Controller/ChangePasswordFOSUser2Controller.php b/Controller/ChangePasswordFOSUser2Controller.php deleted file mode 100644 index d1ee3f4dc..000000000 --- a/Controller/ChangePasswordFOSUser2Controller.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\UserBundle\Controller; - -use FOS\UserBundle\Event\FilterUserResponseEvent; -use FOS\UserBundle\Event\FormEvent; -use FOS\UserBundle\Event\GetResponseUserEvent; -use FOS\UserBundle\Form\Factory\FactoryInterface; -use FOS\UserBundle\FOSUserEvents; -use FOS\UserBundle\Model\UserInterface; -use FOS\UserBundle\Model\UserManagerInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; - -/** - * Controller managing the password change. - * - * This class is inspired from the FOS Change Password Controller - */ -class ChangePasswordFOSUser2Controller extends Controller -{ - /** - * Change user password. - * - * @param Request $request - */ - public function changePasswordAction(Request $request) - { - $user = $this->getUser(); - if (!is_object($user) || !$user instanceof UserInterface) { - throw new AccessDeniedException('This user does not have access to this section.'); - } - - /** @var $dispatcher EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - - $event = new GetResponseUserEvent($user, $request); - $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event); - - if (null !== $event->getResponse()) { - return $event->getResponse(); - } - - /** @var $formFactory FactoryInterface */ - $formFactory = $this->get('fos_user.change_password.form.factory'); - - $form = $formFactory->createForm(); - $form->setData($user); - - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - /** @var $userManager UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - - $event = new FormEvent($form, $request); - $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event); - - $userManager->updateUser($user); - - if (null === $response = $event->getResponse()) { - $url = $this->generateUrl('sonata_user_profile_show'); - $response = new RedirectResponse($url); - } - - $dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); - - return $response; - } - - return $this->render('SonataUserBundle:ChangePassword:changePassword.html.twig', array( - 'form' => $form->createView(), - )); - } -} diff --git a/Controller/ProfileFOSUser2Controller.php b/Controller/ProfileFOSUser2Controller.php deleted file mode 100644 index aed4cb291..000000000 --- a/Controller/ProfileFOSUser2Controller.php +++ /dev/null @@ -1,149 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\UserBundle\Controller; - -use FOS\UserBundle\Event\FilterUserResponseEvent; -use FOS\UserBundle\Event\FormEvent; -use FOS\UserBundle\Event\GetResponseUserEvent; -use FOS\UserBundle\FOSUserEvents; -use FOS\UserBundle\Model\UserInterface; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Security\Core\Exception\AccessDeniedException; - -/** - * This class is inspired from the FOS Profile Controller, except : - * - only twig is supported - * - separation of the user authentication form with the profile form. - */ -class ProfileFOSUser2Controller extends Controller -{ - /** - * @throws AccessDeniedException - * - * @return Response - */ - public function showAction() - { - $user = $this->getUser(); - if (!is_object($user) || !$user instanceof UserInterface) { - throw new AccessDeniedException('This user does not have access to this section.'); - } - - return $this->render('SonataUserBundle:Profile:show.html.twig', array( - 'user' => $user, - 'blocks' => $this->container->getParameter('sonata.user.configuration.profile_blocks'), - )); - } - - /** - * @param Request $request - * - * @return null|RedirectResponse|Response - */ - public function editAuthenticationAction(Request $request) - { - $user = $this->getUser(); - if (!is_object($user) || !$user instanceof UserInterface) { - throw new AccessDeniedException('This user does not have access to this section.'); - } - - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - $event = new GetResponseUserEvent($user, $request); - - if (null !== $event->getResponse()) { - return $event->getResponse(); - } - - /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ - $formFactory = $this->get('fos_user.profile.form.factory'); - $form = $formFactory->createForm(); - $form->setData($user); - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - $userManager->updateUser($user); - $this->addFlash('sonata_user_success', 'profile.flash.updated'); - $response = new RedirectResponse($this->generateUrl('sonata_user_profile_show')); - - return $response; - } - - return $this->render('SonataUserBundle:Profile:edit_authentication.html.twig', array( - 'form' => $form->createView(), - 'breadcrumb_context' => 'user_profile', - )); - } - - /** - * @param Request $request - * - * @throws AccessDeniedException - * - * @return Response - */ - public function editProfileAction(Request $request) - { - $user = $this->getUser(); - if (!is_object($user) || !$user instanceof UserInterface) { - throw new AccessDeniedException('This user does not have access to this section.'); - } - - /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ - $dispatcher = $this->get('event_dispatcher'); - - $event = new GetResponseUserEvent($user, $request); - $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event); - - if (null !== $event->getResponse()) { - return $event->getResponse(); - } - - /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */ - $formFactory = $this->get('fos_user.profile.form.factory'); - - $form = $formFactory->createForm(); - $form->setData($user); - - $form->handleRequest($request); - - if ($form->isSubmitted() && $form->isValid()) { - /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */ - $userManager = $this->get('fos_user.user_manager'); - - $event = new FormEvent($form, $request); - $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event); - - $userManager->updateUser($user); - $this->addFlash('sonata_user_success', 'profile.flash.updated'); - - if (null === $response = $event->getResponse()) { - $url = $this->generateUrl('sonata_user_profile_show'); - $response = new RedirectResponse($url); - } - - $dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response)); - - return $response; - } - - return $this->render('SonataUserBundle:Profile:edit_profile.html.twig', array( - 'form' => $form->createView(), - 'breadcrumb_context' => 'user_profile', - )); - } -} diff --git a/Controller/RegistrationFOSUser2Controller.php b/Controller/RegistrationFOSUser2Controller.php deleted file mode 100644 index 493a5ad0c..000000000 --- a/Controller/RegistrationFOSUser2Controller.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\UserBundle\Controller; - -use FOS\UserBundle\Controller\RegistrationController; - -class RegistrationFOSUser2Controller extends RegistrationController -{ -} diff --git a/Controller/ResettingFOSUser2Controller.php b/Controller/ResettingFOSUser2Controller.php deleted file mode 100644 index 64569bb5b..000000000 --- a/Controller/ResettingFOSUser2Controller.php +++ /dev/null @@ -1,21 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\UserBundle\Controller; - -use FOS\UserBundle\Controller\ResettingController; - -/** - * @author Hugo Briand - */ -class ResettingFOSUser2Controller extends ResettingController -{ -} diff --git a/Controller/SecurityFOSUser2Controller.php b/Controller/SecurityFOSUser2Controller.php deleted file mode 100644 index bf8542bb4..000000000 --- a/Controller/SecurityFOSUser2Controller.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Sonata\UserBundle\Controller; - -use FOS\UserBundle\Controller\SecurityController; -use Sonata\UserBundle\Model\UserInterface; -use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Request; - -class SecurityFOSUser2Controller extends SecurityController -{ - /** - * @param Request $request - * - * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response - */ - public function loginAction(Request $request) - { - $user = $this->getUser(); - - $token = $this->get('security.token_storage')->getToken(); - - if ($token && $token->getUser() instanceof UserInterface) { - $this->addFlash('sonata_user_error', 'sonata_user_already_authenticated'); - $url = $this->get('router')->generate('sonata_user_profile_show'); - - return new RedirectResponse($url); - } - - return parent::loginAction($request); - } -} diff --git a/Resources/config/routing/sonata_change_password_2.xml b/Resources/config/routing/sonata_change_password_2.xml deleted file mode 100644 index 925be42f4..000000000 --- a/Resources/config/routing/sonata_change_password_2.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - SonataUserBundle:ChangePasswordFOSUser2:changePassword - - - SonataUserBundle:ChangePasswordFOSUser2:changePassword - - diff --git a/Resources/config/routing/sonata_profile_2.xml b/Resources/config/routing/sonata_profile_2.xml deleted file mode 100644 index 006d34bc4..000000000 --- a/Resources/config/routing/sonata_profile_2.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - SonataUserBundle:ProfileFOSUser2:show - - - SonataUserBundle:ProfileFOSUser2:editAuthentication - - - SonataUserBundle:ProfileFOSUser2:editProfile - - - SonataUserBundle:ProfileFOSUser2:show - - - SonataUserBundle:ProfileFOSUser2:editAuthentication - - - SonataUserBundle:ProfileFOSUser2:editProfile - - diff --git a/Resources/config/routing/sonata_registration_2.xml b/Resources/config/routing/sonata_registration_2.xml deleted file mode 100644 index 6bb3cc15a..000000000 --- a/Resources/config/routing/sonata_registration_2.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - SonataUserBundle:RegistrationFOSUser2:register - - - SonataUserBundle:RegistrationFOSUser2:checkEmail - - - SonataUserBundle:RegistrationFOSUser2:confirm - - - SonataUserBundle:RegistrationFOSUser2:confirmed - - - SonataUserBundle:RegistrationFOSUser2:register - - - SonataUserBundle:RegistrationFOSUser2:checkEmail - - - SonataUserBundle:RegistrationFOSUser2:confirm - - - SonataUserBundle:RegistrationFOSUser2:confirmed - - diff --git a/Resources/config/routing/sonata_resetting_2.xml b/Resources/config/routing/sonata_resetting_2.xml deleted file mode 100644 index 2da56fb50..000000000 --- a/Resources/config/routing/sonata_resetting_2.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - SonataUserBundle:ResettingFOSUser2:request - - - SonataUserBundle:ResettingFOSUser2:sendEmail - - - SonataUserBundle:ResettingFOSUser2:checkEmail - - - SonataUserBundle:ResettingFOSUser2:reset - - - SonataUserBundle:ResettingFOSUser2:request - - - SonataUserBundle:ResettingFOSUser2:sendEmail - - - SonataUserBundle:ResettingFOSUser2:checkEmail - - - SonataUserBundle:ResettingFOSUser2:reset - - diff --git a/Resources/config/routing/sonata_security_2.xml b/Resources/config/routing/sonata_security_2.xml deleted file mode 100644 index c2280db65..000000000 --- a/Resources/config/routing/sonata_security_2.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - SonataUserBundle:SecurityFOSUser2:login - - - SonataUserBundle:SecurityFOSUser2:check - - - SonataUserBundle:SecurityFOSUser2:logout - - - SonataUserBundle:SecurityFOSUser2:login - - - SonataUserBundle:SecurityFOSUser2:check - - - SonataUserBundle:SecurityFOSUser2:logout - -