我试图使用ResetPasswordbundle重置我的Passort时有错误
我试图在应用程序中重置密码时,我有例外。我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
resetPasswordHelperInterface $ resetPasswordhelper,EntityManagerInterface $ EntityManager
直接放在您的ProcessSendingSendingPassessendingPassessendingPasswordSegpasswordsementpasswordsemail
通过依赖项注入并删除构造函数吗?您也可以删除变量声明。这将解决问题。
问候
Could you put
ResetPasswordHelperInterface $resetPasswordHelper, EntityManagerInterface $entityManager
directly in yourprocessSendingPasswordResetEmail
function via Dependency Injection and remove your constructor ? You can remove the variable declaration too.This will fix the issue.
Regards