gpt4 book ai didi

php - Symfony 3.4 - 确保注释已安装并启用

转载 作者:行者123 更新时间:2023-12-05 04:02:58 25 4
gpt4 key购买 nike

我正在尝试为现有的 Symfony 应用程序实现忘记密码功能。到目前为止,我已经完成了密码请求。用户输入它的电子邮件,然后发送一封带有 token 的电子邮件。返回 URL 如下所示:

/intranet/password-change/f74eab6dca8b5ed6fd46e7893221254b655f94799589e0b83c

通常应该显示一个表单,但是当我访问该 URL 时,我收到此消息:

Class App\Controller\ResettingController does not exist in/public_html/intranet/src/AppBundle/Controller/ (which isbeing imported from "/public_html/intranet/app/config/routing.yml").Make sure annotations are installed and enabled.

我不明白...我在正确的位置设置了 Controller ,路由应该由注释处理。

我的路由文件:

app:
resource: "@AppBundle/Controller/"
type: annotation

coop_tilleuls_forgot_password.reset:
path: '/api/forgot-password'
defaults: { _controller: coop_tilleuls_forgot_password.controller.forgot_password:resetPasswordAction}
methods: [POST]

coop_tilleuls_forgot_password.update:
path: '/api/reset-password/{tokenValue}'
defaults: { _controller: coop_tilleuls_forgot_password.controller.forgot_password:updatePasswordAction}

至于我的重置类,它在/public_html/intranet/src/AppBundle/Controller

看起来像这样:

<?php 
// src/Controller/ResettingController.php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Form\FormErrorIterator;
use App\Entity\User;
use App\Services\Mailer;
use App\Form\ResettingType;
/**
* @Route("/password-change")
*/
class ResettingController extends Controller
{
/**
* @Route("/{id}/{token}", name="resetting")
*/
public function resetting(User $user, $token, Request $request, UserPasswordEncoderInterface $passwordEncoder)
{
// interdit l'accès à la page si:
// le token associé au membre est null
// le token enregistré en base et le token présent dans l'url ne sont pas égaux
// le token date de plus de 10 minutes
if ($user->getToken() === null || $token !== $user->getToken() || !$this->isRequestInTime($user->getPasswordRequestedAt()))
{
throw new AccessDeniedHttpException();
}
$form = $this->createForm(ResettingType::class, $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
// réinitialisation du token à null pour qu'il ne soit plus réutilisable
$user->setToken(null);
$user->setPasswordRequestedAt(null);
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
$request->getSession()->getFlashBag()->add('success', "Votre mot de passe a été modifié.");
return $this->redirectToRoute('security_login_form');
}
return $this->render('security/resetting.html.twig', [
'form' => $form->createView()
]);

}
}

我是 symfony 的新手,所以我可能遗漏了一些明显的东西……我只是没有提前看到它,哈哈,谢谢

最佳答案

只需将 App 替换为 AppBundle

namespace AppBundle\Controller;

关于php - Symfony 3.4 - 确保注释已安装并启用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53925507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com