当我尝试在应用程序中重置密码时出现异常。我使用 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');
}
}
我从应用程序调用请求函数,当在 “$resetToken = $this->resetPasswordHelper->generateResetToken($user);”行中执行 processSendingPasswordResetEmail 函数时出现问题,该函数未执行并返回以下异常:
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
我没有添加任何功能,事实上一切都是按照指南创建的,我不知道为什么会出现错误,请有人帮我解决问题。
ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager
直接放入您的
processSendingPasswordResetEmail
函数中并删除您的构造函数吗?您也可以删除变量声明。这将解决问题。
问候
php bin/console doc:sch:update --dump-sql
,SQL更新了吗?问候,