diff -r 806e57d67020 -r e54dfe4d0b2b vendor/bundles/FOS/UserBundle/Controller/ProfileController.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/bundles/FOS/UserBundle/Controller/ProfileController.php Fri Sep 30 11:24:53 2011 +0200 @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\UserBundle\Controller; + +use Symfony\Component\DependencyInjection\ContainerAware; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; +use FOS\UserBundle\Model\UserInterface; + +/** + * Controller managing the user profile + * + * @author Christophe Coevoet + */ +class ProfileController extends ContainerAware +{ + /** + * Show the user + */ + 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->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user)); + } + + /** + * Edit the user + */ + public function editAction() + { + $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('fos_user.profile.form'); + $formHandler = $this->container->get('fos_user.profile.form.handler'); + + $process = $formHandler->process($user); + if ($process) { + $this->setFlash('fos_user_success', 'profile.flash.updated'); + + return new RedirectResponse($this->container->get('router')->generate('fos_user_profile_show')); + } + + return $this->container->get('templating')->renderResponse( + 'FOSUserBundle:Profile:edit.html.'.$this->container->getParameter('fos_user.template.engine'), + array('form' => $form->createView(), 'theme' => $this->container->getParameter('fos_user.template.theme')) + ); + } + + protected function setFlash($action, $value) + { + $this->container->get('session')->setFlash($action, $value); + } +}