123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- /*
- * This file is part of the FOSUserBundle package.
- *
- * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Sonata\UserBundle\Controller;
- use Symfony\Component\DependencyInjection\ContainerAware;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\Security\Core\Exception\AccessDeniedException;
- use Symfony\Component\HttpFoundation\Response;
- use FOS\UserBundle\Model\UserInterface;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- /**
- * This class is inspirated from the FOS Profile Controller, except :
- * - only twig is supported
- * - separation of the user authentication form with the profile form
- *
- */
- class ProfileController extends Controller
- {
- /**
- * @return Response
- *
- * @throws AccessDeniedException
- */
- public function showAction()
- {
- $user = $this->container->get('security.context')->getToken()->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
- ));
- }
- /**
- * @return Response
- *
- * @throws AccessDeniedException
- */
- public function editAuthenticationAction()
- {
- $user = $this->container->get('security.context')->getToken()->getUser();
- if (!is_object($user) || !$user instanceof UserInterface) {
- throw new AccessDeniedException('This user does not have access to this section.');
- }
- $form = $this->container->get('sonata_user_authentication_form');
- $formHandler = $this->container->get('sonata_user_authentication_form_handler');
- $process = $formHandler->process($user);
- if ($process) {
- $this->setFlash('fos_user_success', 'profile.flash.updated');
- return new RedirectResponse($this->generateUrl('sonata_user_profile_show'));
- }
- return $this->render('SonataUserBundle:Profile:edit_authentication.html.twig', array(
- 'form' => $form->createView(),
- 'theme' => $this->container->getParameter('fos_user.template.theme')
- ));
- }
- /**
- * @return Response
- *
- * @throws AccessDeniedException
- */
- public function editProfileAction()
- {
- $user = $this->container->get('security.context')->getToken()->getUser();
- if (!is_object($user) || !$user instanceof UserInterface) {
- throw new AccessDeniedException('This user does not have access to this section.');
- }
- $form = $this->container->get('sonata.user.profile.form');
- $formHandler = $this->container->get('sonata.user.profile.form.handler');
- $process = $formHandler->process($user);
- if ($process) {
- $this->setFlash('fos_user_success', 'profile.flash.updated');
- return new RedirectResponse($this->generateUrl('sonata_user_profile_show'));
- }
- return $this->render('SonataUserBundle:Profile:edit_profile.html.twig', array(
- 'form' => $form->createView(),
- 'theme' => $this->container->getParameter('fos_user.template.theme')
- ));
- }
- /**
- * @param string $action
- * @param string $value
- */
- protected function setFlash($action, $value)
- {
- $this->container->get('session')->setFlash($action, $value);
- }
- }
|