src/Controller/SiteController.php line 34
<?phpnamespace App\Controller;use App\Entity\Contribution;use App\Entity\ContributionType;use App\Form\ChangePasswordFormType;use Doctrine\ORM\EntityManagerInterface;use Exception;use Symfony\Bridge\Twig\Mime\TemplatedEmail;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\JsonResponse;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Mailer\Exception\TransportExceptionInterface;use Symfony\Component\Mailer\Mailer;use Symfony\Component\Mailer\MailerInterface;use Symfony\Component\Mime\Address;use Symfony\Component\Mime\Email;use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;use Symfony\Component\PasswordHasher\PasswordHasherInterface;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Csrf\TokenGenerator\TokenGeneratorInterface;class SiteController extends AbstractController{public function __construct(private EntityManagerInterface $em,private UserPasswordHasherInterface $passwordHasher,){}public function index(): Response{return $this->redirectToRoute('admin');/*return $this->render('site/index.html.twig', ['controller_name' => 'SiteController',]);*/}public function showProfile(): Response{return $this->render('site/profile.html.twig', ['user' => $this->getUser(),]);}public function modifyPassword(Request $request, MailerInterface $mailer): Response{$user = $this->getUser();$form = $this->createForm(ChangePasswordFormType::class);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {// Encode(hash) the plain password, and set it.$encodedPassword = $this->passwordHasher->hashPassword($user,$form->get('plainPassword')->getData());$user->setPassword($encodedPassword);$this->em->flush();$this->addFlash('success', 'Le mot de passe à bien été réinitialisé');return $this->redirectToRoute('app_profile');}return $this->render('reset_password/reset.html.twig', ['user' => $this->getUser(),'resetForm' => $form->createView(),]);}public function getContributionTypes(Request $request): Response{if ($request->isXmlHttpRequest()){try {$contributionIdSelected = $request->request->get('contribution');$contribution = $this->em->getRepository(Contribution::class)->find(intval($contributionIdSelected));$contributionTypes = $this->em->getRepository(ContributionType::class)->findBy(['contribution' => $contribution]);$contributionTypesArray = [];/* @var ContributionType $contributionType */foreach ($contributionTypes as $contributionType) {$contributionTypesArray[] = ['id' => $contributionType->getId(),'rate' => $contributionType->getRate(),'year' => $contribution->getYear(),'name' => $contributionType->getName(),];}$data = ['success' => true,'contributionTypes' => $contributionTypesArray];} catch (Exception $e) {$data = ['success' => false,'message' => $e,];}} else {die();}return new JsonResponse($data);}}