From f2296bcdcdd57236e68f25ccdfed1a2dd94f36ec Mon Sep 17 00:00:00 2001 From: Dimitri Gritsajuk Date: Wed, 11 Sep 2024 10:10:06 +0200 Subject: [PATCH] Fix Vox magic link email --- config/services.yaml | 1 - src/AppCodeEnum.php | 18 +---- src/BesoinDEurope/App/UrlGenerator.php | 73 ------------------- .../Renaissance/MagicLinkController.php | 16 +--- src/Entity/Adherent.php | 5 -- src/JeMengage/App/AppUrlGenerator.php | 60 --------------- .../Ensemble/EnsembleMagicLinkMessage.php | 21 ------ src/OAuth/App/AuthAppUrlManager.php | 3 +- src/Renaissance/App/UrlGenerator.php | 6 +- src/Security/LoginFormGuardAuthenticator.php | 2 +- 10 files changed, 11 insertions(+), 194 deletions(-) delete mode 100644 src/BesoinDEurope/App/UrlGenerator.php delete mode 100644 src/JeMengage/App/AppUrlGenerator.php delete mode 100644 src/Mailer/Message/Ensemble/EnsembleMagicLinkMessage.php diff --git a/config/services.yaml b/config/services.yaml index d79b9cfc293..2cd816f5c21 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -60,7 +60,6 @@ services: $renaissanceHost: '%app_renaissance_host%' $adminRenaissanceHost: '%admin_renaissance_host%' $jemengageHost: '%jemengage_host%' - $jemengageAuthHost: '%jemengage_auth_host%' $avecvousHost: '%avecvous_host%' $userBesoinDEuropeHost: '%env(USER_BESOINDEUROPE_HOST)%' $userVoxHost: '%user_vox_host%' diff --git a/src/AppCodeEnum.php b/src/AppCodeEnum.php index cbe439cd827..be825f5c6b4 100644 --- a/src/AppCodeEnum.php +++ b/src/AppCodeEnum.php @@ -11,25 +11,9 @@ final class AppCodeEnum extends Enum public const BESOIN_D_EUROPE = 'besoindeurope'; public const LEGISLATIVE = 'legislative'; public const VOX = 'vox'; - public const JEMENGAGE = 'jemengage'; public const JEMENGAGE_WEB = 'jemengage_web'; public const JEMENGAGE_MOBILE = 'jemengage_mobile'; - public static function getJemangageAppCodes(): array - { - return [ - self::JEMENGAGE, - self::JEMENGAGE_WEB, - self::JEMENGAGE_MOBILE, - self::BESOIN_D_EUROPE, - ]; - } - - public static function isJeMengage(?string $code): bool - { - return \in_array($code, static::getJemangageAppCodes(), true); - } - public static function isRenaissanceApp(?string $code): bool { return self::RENAISSANCE === $code; @@ -37,6 +21,6 @@ public static function isRenaissanceApp(?string $code): bool public static function isMobileApp(?string $appCode): bool { - return \in_array($appCode, [self::BESOIN_D_EUROPE, self::LEGISLATIVE]); + return \in_array($appCode, [self::BESOIN_D_EUROPE, self::LEGISLATIVE, self::VOX]); } } diff --git a/src/BesoinDEurope/App/UrlGenerator.php b/src/BesoinDEurope/App/UrlGenerator.php deleted file mode 100644 index 52b415bf338..00000000000 --- a/src/BesoinDEurope/App/UrlGenerator.php +++ /dev/null @@ -1,73 +0,0 @@ -appHost = $userBesoinDEuropeHost; - } - - public static function getAppCode(): string - { - return AppCodeEnum::BESOIN_D_EUROPE; - } - - public function generateHomepageLink(): string - { - return $this->urlGenerator->generate('besoindeurope_site', [], UrlGeneratorInterface::ABSOLUTE_URL); - } - - public function generateForLoginSuccess(Adherent $adherent): string - { - return $this->urlGenerator->generate('vox_app_redirect'); - } - - public function generateForLogoutSuccess(Request $request): string - { - $client = $this->clientRepository->getVoxClient(); - $redirectUri = $request->query->get('redirect_uri'); - - if (!$redirectUri || !\in_array($redirectUri, $client->getRedirectUris())) { - return current($client->getRedirectUris()); - } - - return $redirectUri; - } - - public function generateSuccessResetPasswordLink(Request $request): string - { - return $this->generateLoginLink(); - } - - public function generateLoginLink(): string - { - return $this->urlGenerator->generate('app_besoindeurope_login'); - } - - public function guessAppCodeFromRequest(Request $request): ?string - { - if ($request->attributes->get('app_domain', $request->getHost()) === $this->appHost) { - return static::getAppCode(); - } - - return null; - } - - public function getAppHost(): string - { - return $this->appHost; - } -} diff --git a/src/Controller/Renaissance/MagicLinkController.php b/src/Controller/Renaissance/MagicLinkController.php index 85f662aec27..216170295ad 100644 --- a/src/Controller/Renaissance/MagicLinkController.php +++ b/src/Controller/Renaissance/MagicLinkController.php @@ -5,7 +5,6 @@ use App\AppCodeEnum; use App\Entity\Administrator; use App\Mailer\MailerService; -use App\Mailer\Message\Ensemble\EnsembleMagicLinkMessage; use App\Mailer\Message\Renaissance\RenaissanceMagicLinkMessage; use App\OAuth\App\AuthAppUrlManager; use App\Repository\AdherentRepository; @@ -27,16 +26,13 @@ public function getMagicLinkAction( AdherentRepository $adherentRepository, MailerService $transactionalMailer, TranslatorInterface $translator, - AuthAppUrlManager $appUrlManager, ): Response { - $appUrlGenerator = $appUrlManager->getUrlGenerator($appCode = $appUrlManager->getAppCodeFromRequest($request) ?? AppCodeEnum::RENAISSANCE); - if ($user = $this->getUser()) { if ($user instanceof Administrator) { return $this->redirectToRoute('admin_app_adherent_list'); } - return $this->redirect($appUrlGenerator->generateForLoginSuccess($user)); + return $this->redirectToRoute('vox_app_redirect'); } $form = $this @@ -48,18 +44,14 @@ public function getMagicLinkAction( $email = $form->getData(); if ($adherent = $adherentRepository->findOneActiveByEmail($email)) { - $loginLink = $loginLinkHandler->createLoginLink($adherent, $request, $appCode); + $loginLink = $loginLinkHandler->createLoginLink($adherent, $request, AppCodeEnum::VOX); - if (AppCodeEnum::isMobileApp($appCode)) { - $transactionalMailer->sendMessage(EnsembleMagicLinkMessage::create($adherent, $loginLink->getUrl())); - } else { - $transactionalMailer->sendMessage(RenaissanceMagicLinkMessage::create($adherent, $loginLink->getUrl())); - } + $transactionalMailer->sendMessage(RenaissanceMagicLinkMessage::create($adherent, $loginLink->getUrl())); } $this->addFlash('info', $translator->trans('adherent.get_magic_link.email_sent', ['%email%' => $email])); - return $this->redirectToRoute('app_user_get_magic_link', ['app_domain' => $appUrlGenerator->getAppHost()]); + return $this->redirectToRoute('app_user_get_magic_link'); } return $this->render('security/renaissance_user_magic_link.html.twig', ['form' => $form->createView()]); diff --git a/src/Entity/Adherent.php b/src/Entity/Adherent.php index ba08367a5f7..4510eb89c87 100644 --- a/src/Entity/Adherent.php +++ b/src/Entity/Adherent.php @@ -2170,11 +2170,6 @@ public function setSource(?string $source): void $this->source = $source; } - public function isJemengageUser(): bool - { - return MembershipSourceEnum::JEMENGAGE === $this->source; - } - public function isRenaissanceUser(): bool { return MembershipSourceEnum::RENAISSANCE === $this->source; diff --git a/src/JeMengage/App/AppUrlGenerator.php b/src/JeMengage/App/AppUrlGenerator.php deleted file mode 100644 index 64cdec84ce5..00000000000 --- a/src/JeMengage/App/AppUrlGenerator.php +++ /dev/null @@ -1,60 +0,0 @@ -appHost = $jemengageHost; - $this->appAuthHost = $jemengageAuthHost; - } - - public static function getAppCode(): string - { - return AppCodeEnum::JEMENGAGE; - } - - public function guessAppCodeFromRequest(Request $request): ?string - { - if ($request->attributes->get('app_domain', $request->getHost()) === $this->appAuthHost) { - return static::getAppCode(); - } - - return null; - } - - public function generateHomepageLink(): string - { - return $this->appHost; - } - - public function generateSuccessResetPasswordLink(Request $request): string - { - if ($request->query->has('is_creation')) { - return $this->urlGenerator->generate('app_jemengage_creation_confirmation'); - } - - return '//'.$this->appAuthHost; - } - - public function generateLoginLink(): string - { - return $this->urlGenerator->generate('app_jemengage_login'); - } - - public function getAppHost(): string - { - return $this->appAuthHost; - } -} diff --git a/src/Mailer/Message/Ensemble/EnsembleMagicLinkMessage.php b/src/Mailer/Message/Ensemble/EnsembleMagicLinkMessage.php deleted file mode 100644 index 319af68d5dc..00000000000 --- a/src/Mailer/Message/Ensemble/EnsembleMagicLinkMessage.php +++ /dev/null @@ -1,21 +0,0 @@ -getEmailAddress(), - $adherent->getFullName(), - 'Votre lien de connexion', - [], - ['magic_link' => $url], - ); - } -} diff --git a/src/OAuth/App/AuthAppUrlManager.php b/src/OAuth/App/AuthAppUrlManager.php index ec59a9928e3..5d6fc2cb12c 100644 --- a/src/OAuth/App/AuthAppUrlManager.php +++ b/src/OAuth/App/AuthAppUrlManager.php @@ -2,6 +2,7 @@ namespace App\OAuth\App; +use App\AppCodeEnum; use Symfony\Component\HttpFoundation\Request; class AuthAppUrlManager @@ -16,7 +17,7 @@ public function __construct(iterable $urlGenerators) public function getUrlGenerator(string $appCode): AuthAppUrlGeneratorInterface { - return $this->urlGenerators[$appCode]; + return $this->urlGenerators[$appCode] ?? $this->urlGenerators[AppCodeEnum::RENAISSANCE]; } public function getAppCodeFromRequest(Request $request): ?string diff --git a/src/Renaissance/App/UrlGenerator.php b/src/Renaissance/App/UrlGenerator.php index 47516767591..e1e2741ce48 100644 --- a/src/Renaissance/App/UrlGenerator.php +++ b/src/Renaissance/App/UrlGenerator.php @@ -12,11 +12,11 @@ class UrlGenerator extends AbstractAppUrlGenerator { private string $appHost; - public function __construct(UrlGeneratorInterface $urlGenerator, string $renaissanceHost) + public function __construct(UrlGeneratorInterface $urlGenerator, string $userVoxHost) { parent::__construct($urlGenerator); - $this->appHost = $renaissanceHost; + $this->appHost = $userVoxHost; } public static function getAppCode(): string @@ -31,7 +31,7 @@ public function generateHomepageLink(): string public function generateForLoginSuccess(Adherent $adherent): string { - return $this->urlGenerator->generate('app_renaissance_adherent_space'); + return $this->urlGenerator->generate('vox_app_redirect'); } public function generateSuccessResetPasswordLink(Request $request): string diff --git a/src/Security/LoginFormGuardAuthenticator.php b/src/Security/LoginFormGuardAuthenticator.php index 95d5508b530..6a9742da737 100644 --- a/src/Security/LoginFormGuardAuthenticator.php +++ b/src/Security/LoginFormGuardAuthenticator.php @@ -151,7 +151,7 @@ public function start(Request $request, ?AuthenticationException $authException return parent::start($request, $authException); } - protected function getLoginUrl() + protected function getLoginUrl(): string { if ($this->currentAppCode) { return $this->appUrlManager->getUrlGenerator($this->currentAppCode)->generateLoginLink();