Bonjour, j’essaie de faire en sorte que l’utilisateur puisse changer son password mais lorsque je tape a la fin de mon code "user−>setPassword(password);" il me met un message d’erreur "undefined method setPassword", comme s’il n’avait pas accès aux méthodes de ma classes User. Je vous envoie mon code ci_dessous:
<?php
namespace App\Controller;
use App\Form\ChangePasswordType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Doctrine\ORM\EntityManagerInterface;
class AccountPasswordController extends AbstractController
{
/**
* @Route("/compte/modifier-mdp", name="account_password")
*/
public function index(Request $request,UserPasswordHasherInterface $encodage,EntityManagerInterface $doctrine): Response
{
$user = $this->getUser();
$form = $this->createForm(ChangePasswordType::class, $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$old_pwd = $form->get('old_password')->getData();
if($encodage->isPasswordValid($user,$old_pwd)){
$new_pwd= $form->get('new_password')->getData();
$password = $encodage->hashPassword($user, $new_pwd);
$user->setPassword($password);
$doctrine->persist($user);
$doctrine->flush();
}
}
return $this->render('account/password.html.twig',[
'form'=>$form->createView()
]);
}
}
+0
-0