src/Controller/Website/PartnerAuthController.php line 23

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Website;
  4. use App\Helper\Partner\PartnerHelper;
  5. use App\Helper\SuluHelper;
  6. use Croisiland\CommonBundle\Partner\AuthenticateForm\PartnerAuthenticateFormProviderInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. class PartnerAuthController extends AbstractController
  12. {
  13. public function __construct(
  14. private readonly PartnerHelper $partnerHelper,
  15. private readonly SuluHelper $suluHelper,
  16. private readonly PartnerAuthenticateFormProviderInterface $authenticateFormProvider,
  17. ) {}
  18. public function authForm(Request $request, SessionInterface $session): Response
  19. {
  20. $partner = $this->partnerHelper->getCurrentPartner();
  21. if ($partner === null) {
  22. throw $this->createNotFoundException('Partenaire non trouvé.');
  23. }
  24. if ($this->authenticateFormProvider->needExternalFormAuthentification($partner)) {
  25. return $this->redirect(
  26. $this->authenticateFormProvider->getExternalFormAuthentificationUrl($partner)
  27. );
  28. }
  29. $form = $this->authenticateFormProvider->getForm($partner, null, null, true);
  30. $form->handleRequest($request);
  31. if ($form->isSubmitted() && $form->isValid()) {
  32. $session->set($this->partnerHelper->getPartnerSessionKey($partner), true);
  33. // TODO redirect to referer using SULU tools
  34. return $this->redirect(
  35. $this->suluHelper->getContentRootPath()
  36. );
  37. }
  38. return $this->render('partner/auth_form.html.twig', [
  39. 'form' => $form->createView(),
  40. ]);
  41. }
  42. public function logout(SessionInterface $session): Response
  43. {
  44. $partner = $this->partnerHelper->getCurrentPartner();
  45. if ($partner === null) {
  46. return $this->redirect(
  47. $this->suluHelper->getContentRootPath()
  48. );
  49. }
  50. $session->remove($this->partnerHelper->getPartnerSessionKey($partner));
  51. return $this->redirectToRoute('website_partner_auth.login');
  52. }
  53. }