public function changePasswordAction(Request $request, $token)
 {
     /** @var UserPasswordResetInterface $user */
     $user = $this->userRepository->findUserByConfirmationToken($token);
     if (null === $user) {
         throw new NotFoundHttpException();
     }
     if (!$user->isPasswordRequestNonExpired($this->tokenTtl)) {
         throw new NotFoundHttpException();
     }
     $form = $this->formFactory->create('admin_password_reset_change_password', $user);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $user->setConfirmationToken(null);
         $user->setPasswordRequestedAt(null);
         $this->userRepository->save($user);
         $request->getSession()->getFlashBag()->add('success', 'admin.change_password_message.success');
         return new RedirectResponse($this->router->generate('fsi_admin_security_user_login'));
     }
     return $this->templating->renderResponse($this->changePasswordActionTemplate, array('form' => $form->createView()));
 }
 /**
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \FSi\Bundle\AdminSecurityBundle\Model\UserRepositoryInterface $userRepository
  * @param \FSi\Bundle\AdminSecurityBundle\Model\UserPasswordResetInterface $user
  * @param \Symfony\Component\Form\FormFactoryInterface $formFactory
  * @param \Symfony\Component\Form\FormInterface $form
  * @param \Symfony\Component\HttpFoundation\Session\Session $session
  * @param \Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface $flashBag
  * @param \Symfony\Component\Routing\RouterInterface $router
  */
 function it_changes_password($request, $userRepository, $user, $formFactory, $form, $session, $flashBag, $router)
 {
     $userRepository->findUserByConfirmationToken('token12345')->willReturn($user);
     $user->isPasswordRequestNonExpired(3600 * 12)->willReturn(true);
     $formFactory->create('admin_password_reset_change_password', $user)->willReturn($form);
     $form->handleRequest($request)->shouldBeCalled();
     $form->isValid()->willReturn(true);
     $user->setConfirmationToken(null)->shouldBeCalled();
     $user->setPasswordRequestedAt(null)->shouldBeCalled();
     $userRepository->save($user)->shouldBeCalled();
     $request->getSession()->willReturn($session);
     $session->getFlashBag()->willReturn($flashBag);
     $flashBag->add('success', 'admin.change_password_message.success')->shouldBeCalled();
     $router->generate('fsi_admin_security_user_login')->willReturn('url');
     $response = $this->changePasswordAction($request, 'token12345');
     $response->shouldHaveType('Symfony\\Component\\HttpFoundation\\RedirectResponse');
 }