我试图使用ResetPasswordbundle重置我的Passort时有错误

发布于 2025-02-01 04:09:07 字数 4064 浏览 4 评论 0原文

我试图在应用程序中重置密码时,我有例外。我使用Symfony 4.4并安装了“ Symfonycasts/reset-password-bundle”:“^1.13”,控制器是下一个:

class ResetPasswordController extends AbstractController {
    use ResetPasswordControllerTrait;
    private $resetPasswordHelper;
    private $entityManager;
    public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager)
    {
        $this->resetPasswordHelper = $resetPasswordHelper;
        $this->entityManager = $entityManager;
    }

    /**
     * Display & process form to request a password reset.
     *
     * @Route("", name="app_forgot_password_request")
     */
    public function request(Request $request, MailerInterface $mailer, TranslatorInterface $translator): Response
    {
        $form = $this->createForm(ResetPasswordRequestFormType::class);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            return $this->processSendingPasswordResetEmail(
                $form->get('email')->getData(),
                $mailer,
                $translator
            );
        }
        return $this->render('reset_password/request.html.twig', [
            'requestForm' => $form->createView(),
        ]);
    }

    private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer, TranslatorInterface $translator): RedirectResponse
    {
        $user = $this->entityManager->getRepository(User::class)->findOneBy([
            'email' => $emailFormData,
        ]);
        // Do not reveal whether a user account was found or not.
        if (!$user) {
            return $this->redirectToRoute('app_check_email');
        }
        try {
            $resetToken = $this->resetPasswordHelper->generateResetToken($user);
        } catch (ResetPasswordExceptionInterface $e) {
            return new Response(json_encode(['message' => $e->getMessage()]), 500, ['Content-Type' => 'application/json']);
            // If you want to tell the user why a reset email was not sent, uncomment
            // the lines below and change the redirect to 'app_forgot_password_request'.
            // Caution: This may reveal if a user is registered or not.
            //
            // $this->addFlash('reset_password_error', sprintf(
            //     '%s - %s',
            //     $translator->trans(ResetPasswordExceptionInterface::MESSAGE_PROBLEM_HANDLE, [], 'ResetPasswordBundle'),
            //     $translator->trans($e->getReason(), [], 'ResetPasswordBundle')
            // ));

            return $this->redirectToRoute('app_check_email');
        }

        $email = (new TemplatedEmail())
            ->from(new Address('[email protected]', 'Yoke Integration Suite'))
            ->to($user->getEmail())
            ->subject('Your password reset request')
            ->htmlTemplate('reset_password/email.html.twig')
            ->context([
                'resetToken' => $resetToken,
            ])
        ;

        $mailer->send($email);

        // Store the token object in session for retrieval in check-email route.
        $this->setTokenObjectInSession($resetToken);

        return $this->redirectToRoute('app_check_email');
    }
}

我从App中调用了请求函数,并且当processSendingPassingPasswordWordReseTemail函数在行中执行时发生问题>“ $ resettoken = $ this-> resetpasswordhelper-> generateresettoken($ user);” ,该函数未执行并返回以下例外:

An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'expires_at' in 'where clause'

我遵循安装指南以在下一个上添加重置密码页面:

https://symfony.com/doc/4.4/security/reset_password.html
https://github.com/symfonycasts/reset-password-bundle

我没有添加任何功能,实际上所有功能都是指示所示的,我不知道为什么发生错误,有人可以帮助我解决问题。

I have an exception whe I try to reset password in my app. I use Symfony 4.4 and and installed "symfonycasts/reset-password-bundle": "^1.13", the controller is the next:

class ResetPasswordController extends AbstractController {
    use ResetPasswordControllerTrait;
    private $resetPasswordHelper;
    private $entityManager;
    public function __construct(ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager)
    {
        $this->resetPasswordHelper = $resetPasswordHelper;
        $this->entityManager = $entityManager;
    }

    /**
     * Display & process form to request a password reset.
     *
     * @Route("", name="app_forgot_password_request")
     */
    public function request(Request $request, MailerInterface $mailer, TranslatorInterface $translator): Response
    {
        $form = $this->createForm(ResetPasswordRequestFormType::class);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            return $this->processSendingPasswordResetEmail(
                $form->get('email')->getData(),
                $mailer,
                $translator
            );
        }
        return $this->render('reset_password/request.html.twig', [
            'requestForm' => $form->createView(),
        ]);
    }

    private function processSendingPasswordResetEmail(string $emailFormData, MailerInterface $mailer, TranslatorInterface $translator): RedirectResponse
    {
        $user = $this->entityManager->getRepository(User::class)->findOneBy([
            'email' => $emailFormData,
        ]);
        // Do not reveal whether a user account was found or not.
        if (!$user) {
            return $this->redirectToRoute('app_check_email');
        }
        try {
            $resetToken = $this->resetPasswordHelper->generateResetToken($user);
        } catch (ResetPasswordExceptionInterface $e) {
            return new Response(json_encode(['message' => $e->getMessage()]), 500, ['Content-Type' => 'application/json']);
            // If you want to tell the user why a reset email was not sent, uncomment
            // the lines below and change the redirect to 'app_forgot_password_request'.
            // Caution: This may reveal if a user is registered or not.
            //
            // $this->addFlash('reset_password_error', sprintf(
            //     '%s - %s',
            //     $translator->trans(ResetPasswordExceptionInterface::MESSAGE_PROBLEM_HANDLE, [], 'ResetPasswordBundle'),
            //     $translator->trans($e->getReason(), [], 'ResetPasswordBundle')
            // ));

            return $this->redirectToRoute('app_check_email');
        }

        $email = (new TemplatedEmail())
            ->from(new Address('[email protected]', 'Yoke Integration Suite'))
            ->to($user->getEmail())
            ->subject('Your password reset request')
            ->htmlTemplate('reset_password/email.html.twig')
            ->context([
                'resetToken' => $resetToken,
            ])
        ;

        $mailer->send($email);

        // Store the token object in session for retrieval in check-email route.
        $this->setTokenObjectInSession($resetToken);

        return $this->redirectToRoute('app_check_email');
    }
}

I called the request function from app and the problem occured when the processSendingPasswordResetEmail function is executed in the line "$resetToken = $this->resetPasswordHelper->generateResetToken($user);" , the function is not executed and returns the following exception:

An exception occurred while executing a query: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'expires_at' in 'where clause'

I followed the installation guide to add reset password feature on the next page:

https://symfony.com/doc/4.4/security/reset_password.html
https://github.com/symfonycasts/reset-password-bundle

I did not add any function, in fact everything is created by the guide as indicated and I do not know why the error occurs, could someone help me solve the problem please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

゛清羽墨安 2025-02-08 04:09:07

您可以将resetPasswordHelperInterface $ resetPasswordhelper,EntityManagerInterface $ EntityManager直接放在您的ProcessSendingSendingPassessendingPassessendingPasswordSegpasswordsementpasswordsemail通过依赖项注入并删除构造函数吗?您也可以删除变量声明。

这将解决问题。

问候

Could you put ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager directly in your processSendingPasswordResetEmail function via Dependency Injection and remove your constructor ? You can remove the variable declaration too.

This will fix the issue.

Regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文