我已经为symfony2用户重置密码编写了重置操作。这是代码:
/**
* @Route("/reset-password/{confirmationToken}", name="user_resetting_confirm")
* @ParamConverter("confirmationToken", class="MyProjectBundle:User")
* @param \My\Project\Entity\User $user
* @Template()
*/
public function resetAction(Request $request, $confirmationToken)
{
$form = $this->createFormBuilder()
->add('password', 'repeated', array(
'type' => 'password',
'first_name' => 'New Password',
'second_name' => 'Confirm New Password',
'invalid_message' => 'Passwords don\'t match',
'error_bubbling' => true,
))
->getForm();
if ('POST' == $request->getMethod()) {
$form->bindRequest($request);
$data = $form->getData();
$user = $this->container->get('fos_user.user_manager')->findUserByConfirmationToken($confirmationToken);
if (null === $user) {
throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $confirmationToken));
}
if (!$user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
return new RedirectResponse($this->container->get('router')->generate('fos_user_resetting_request'));
}
if ($form->isValid()) {
$newPassword = $data['password'];
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword($newPassword, $user->getSalt());
$user->setPassword($password);
$em = $this->get('doctrine')->getEntityManager();
$em->persist($user);
$em->flush();
$this->authenticateUser($user);
return new RedirectResponse($this->getRedirectionUrl($user));
}
}
return $this->render('MyProjectBundle:Resetting:password_reset.html.twig',array('form' => $form->createView()));
}
出于某种原因,如果我在两个字段中输入错误的密码然后提交我得到一个没有HTML代码的空白页面。 这里有什么问题吗?