Controller/Frontend/ChangePasswordController.php
public function changePasswordAction()
    {
        $user = $this->getUser();
        if (!is_object($user) || !$user instanceof UserInterface) {
            $this->createAccessDeniedException('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())
        );
    }
public function changePasswordAction()
    {
        $user = $this->getUser();
        if (!is_object($user) || !$user instanceof UserInterface) {
            $this->createAccessDeniedException('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())
        );
    }
@return Response|RedirectResponse

@throws AccessDeniedException