Skip to content

Commit

Permalink
Fix Vox magic link email
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Sep 11, 2024
1 parent ae96d8d commit f2296bc
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 194 deletions.
1 change: 0 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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%'
Expand Down
18 changes: 1 addition & 17 deletions src/AppCodeEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,16 @@ 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;
}

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]);
}
}
73 changes: 0 additions & 73 deletions src/BesoinDEurope/App/UrlGenerator.php

This file was deleted.

16 changes: 4 additions & 12 deletions src/Controller/Renaissance/MagicLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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()]);
Expand Down
5 changes: 0 additions & 5 deletions src/Entity/Adherent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 0 additions & 60 deletions src/JeMengage/App/AppUrlGenerator.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/Mailer/Message/Ensemble/EnsembleMagicLinkMessage.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/OAuth/App/AuthAppUrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\OAuth\App;

use App\AppCodeEnum;
use Symfony\Component\HttpFoundation\Request;

class AuthAppUrlManager
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Renaissance/App/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Security/LoginFormGuardAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit f2296bc

Please sign in to comment.