public function updatePasswordAction(Request $request)
    {
        $user = $this->getUser();
        $form = $this->createForm(ChangePasswordType::class);

        $form->bind($request);
        $data = $form->getData();

        /** @var $factory \Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface */
        $factory = $this->get('security.encoder_factory');
        $encoder = $factory->getEncoder($user);
        $current = $encoder->encodePassword($data['current'], $user->getSalt());

        if ($current !== $user->getPassword()) {
            $form->get('current')->addError(new FormError('Current password is not correct'));
        }

        if ($form->isValid()) {
            $user->setPassword($encoder->encodePassword($data['password'], $user->getSalt()));

            $em = $this->getDoctrine()->getManager();
            $em->persist($user);
            $em->flush();

            $this->get('session')->getFlashBag()->set('success', 'Your password has been changed.');

            return new JsonReloadResponse();
        }

        return new JsonErrorResponse($form);
    }