vendor/bundles/FOS/UserBundle/Controller/ProfileController.php
changeset 3 e54dfe4d0b2b
equal deleted inserted replaced
2:806e57d67020 3:e54dfe4d0b2b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the FOSUserBundle package.
       
     5  *
       
     6  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace FOS\UserBundle\Controller;
       
    13 
       
    14 use Symfony\Component\DependencyInjection\ContainerAware;
       
    15 use Symfony\Component\HttpFoundation\RedirectResponse;
       
    16 use Symfony\Component\Security\Core\Exception\AccessDeniedException;
       
    17 use FOS\UserBundle\Model\UserInterface;
       
    18 
       
    19 /**
       
    20  * Controller managing the user profile
       
    21  *
       
    22  * @author Christophe Coevoet <stof@notk.org>
       
    23  */
       
    24 class ProfileController extends ContainerAware
       
    25 {
       
    26     /**
       
    27      * Show the user
       
    28      */
       
    29     public function showAction()
       
    30     {
       
    31         $user = $this->container->get('security.context')->getToken()->getUser();
       
    32         if (!is_object($user) || !$user instanceof UserInterface) {
       
    33             throw new AccessDeniedException('This user does not have access to this section.');
       
    34         }
       
    35 
       
    36         return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user));
       
    37     }
       
    38 
       
    39     /**
       
    40      * Edit the user
       
    41      */
       
    42     public function editAction()
       
    43     {
       
    44         $user = $this->container->get('security.context')->getToken()->getUser();
       
    45         if (!is_object($user) || !$user instanceof UserInterface) {
       
    46             throw new AccessDeniedException('This user does not have access to this section.');
       
    47         }
       
    48 
       
    49         $form = $this->container->get('fos_user.profile.form');
       
    50         $formHandler = $this->container->get('fos_user.profile.form.handler');
       
    51 
       
    52         $process = $formHandler->process($user);
       
    53         if ($process) {
       
    54             $this->setFlash('fos_user_success', 'profile.flash.updated');
       
    55 
       
    56             return new RedirectResponse($this->container->get('router')->generate('fos_user_profile_show'));
       
    57         }
       
    58 
       
    59         return $this->container->get('templating')->renderResponse(
       
    60             'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'),
       
    61             array('form' => $form->createView(), 'theme' => $this->container->getParameter('fos_user.template.theme'))
       
    62         );
       
    63     }
       
    64 
       
    65     protected function setFlash($action, $value)
       
    66     {
       
    67         $this->container->get('session')->setFlash($action, $value);
       
    68     }
       
    69 }