12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- /*
- * This file is part of the Sonata Project package.
- *
- * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
- *
- * 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\Model\UserInterface;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
- use Symfony\Component\HttpFoundation\RedirectResponse;
- use Symfony\Component\HttpFoundation\Response;
- /**
- * This class is inspired from the FOS Change Password Controller.
- *
- * @author Hugo Briand <briand@ekino.com>
- */
- class ChangePasswordFOSUser1Controller extends Controller
- {
- /**
- * @return Response|RedirectResponse
- *
- * @throws AccessDeniedException
- */
- public function changePasswordAction()
- {
- $user = $this->getUser();
- if (!is_object($user) || !$user instanceof UserInterface) {
- throw new AccessDeniedException('This user does not have access to this section.');
- }
- $form = $this->get('fos_user.change_password.form');
- $formHandler = $this->get('fos_user.change_password.form.handler');
- $process = $formHandler->process($user);
- if ($process) {
- $this->setFlash('fos_user_success', 'change_password.flash.success');
- return $this->redirect($this->getRedirectionUrl($user));
- }
- return $this->render(
- 'SonataUserBundle:ChangePassword:changePassword.html.'.$this->container->getParameter('fos_user.template.engine'),
- array('form' => $form->createView())
- );
- }
- /**
- * @param UserInterface $user
- *
- * @return string
- */
- protected function getRedirectionUrl(UserInterface $user)
- {
- return $this->generateUrl('sonata_user_profile_show');
- }
- /**
- * @param string $action
- * @param string $value
- */
- protected function setFlash($action, $value)
- {
- $this->get('session')->getFlashBag()->set($action, $value);
- }
- }
|