在 Symfony 4 中重置密码

Reset password in Symfony 4

我坚持在 Symfony 4 中实现重设密码。在这里,用户以忘记密码的形式插入一封电子邮件,然后他收到一封带有 link 的电子邮件,该电子邮件指向重设密码的形式.我的忘记密码控制器中有以下方法:

/**
 * @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 包含电子邮件和带有重置密码 link 的标识符。但它显示以下错误

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.

谁能告诉我这里出了什么问题?我生成 URL 的方法可以吗?

非常感谢!

嗯,你没有 post 整个方法,包括路由部分,但我假设你在你的注释中忘记了做这样的事情 /password/reset/{token} 类似于

@Route("/{id}/edit", name="portofolio_album_edit", methods="GET|POST")