我被困在Symfony 4中实现重设密码。在这里,用户以忘记密码的形式插入一封电子邮件,然后他收到一封电子邮件,其中包含指向重设密码形式的链接。我的忘记密码控制器中有以下方法:
/**
* @Route("/forgot-password", name="forgot_password", defaults={"email=null"})
* @Method({"GET","POST"})
* @param Request $request
* @param AuthenticationUtils $authenticationUtils
* @param UserPasswordEncoderInterface $passwordEncoder
* @param $email
* @return Response
*/
public function forgotpass(Request $request, \Swift_Mailer $mailer)
{
$form = $this->createForm(ForgotPassType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$email = $form->getData();
$users = $this->getDoctrine()
->getRepository(Users::class)
->findOneBy(array('email' => $email['email']));
$identifier = random_bytes(10);
$url = $this->generateUrl('reset_password', array('email'=>$email['email'], 'identifier'=>$identifier));
return $this->redirectToRoute('url');
}
我正在尝试生成将通过电子邮件发送以重置密码的URL。该URL包含电子邮件和带有重置密码链接的标识符。但它显示以下错误
Unable to generate a URL for the named route "http://myweb.test/reset-password?email=email%40gmail.com&identifier=%EEJ8f%A2%DEN%F0%01A" as such route does not exist.
有人可以告诉我这里出了什么问题吗?我生成网址的方法可以吗?
非常感谢!
答案 0 :(得分:0)
好吧,您没有发布包括路由部分在内的整个方法,但我认为在您的注释中您忘了做类似/ password / reset / {token}之类的事情
@Route("/{id}/edit", name="portofolio_album_edit", methods="GET|POST")