I am trying to implement a forgot password feature to an existing Symfony app. So fare I have the password request done. The user puts in it’s email and an email is sent with a token. The return URL looks like this:
/intranet/password-change/f74eab6dca8b5ed6fd46e7893221254b655f94799589e0b83c
Normally a forme should show but when i visite that URL i get this message:
Class AppControllerResettingController does not exist in /public_html/intranet/src/AppBundle/Controller/ (which is being imported from “/public_html/intranet/app/config/routing.yml”). Make sure annotations are installed and enabled.
I don’t get it … I have the controller set up at the right place and the route should be taken care of by the annotations.
My routing file:
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}
as for my resseting class it’s in /public_html/intranet/src/AppBundle/Controller
And looks like this:
<?php
// src/Controller/ResettingController.php
namespace AppController;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentValidatorConstraintsEmail;
use SymfonyComponentValidatorConstraintsNotBlank;
use SymfonyComponentFormExtensionCoreTypeEmailType;
use SymfonyComponentSecurityCsrfTokenGeneratorTokenGeneratorInterface;
use SymfonyComponentHttpKernelExceptionAccessDeniedHttpException;
use SymfonyComponentValidatorValidatorValidatorInterface;
use SymfonyComponentTranslationTranslatorInterface;
use SymfonyComponentSecurityCoreEncoderUserPasswordEncoderInterface;
use SymfonyComponentFormFormErrorIterator;
use AppEntityUser;
use AppServicesMailer;
use AppFormResettingType;
/**
* @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()
]);
}
}
I am new to symfony so I might be missing something obvious … I just don’t see it lol thx in advance
Advertisement
Answer
JUst replace App by AppBundle
namespace AppBundleController;