Browse Source

add sauvagerie as possible contact recipient

olinox14 4 months ago
parent
commit
925b7951d8
3 changed files with 18 additions and 6 deletions
  1. 3 2
      .env
  2. 1 0
      config/services.yaml
  3. 14 4
      src/State/Processor/ContactRequestProcessor.php

+ 3 - 2
.env

@@ -8,7 +8,7 @@ DATABASE_URL="none"
 ###< doctrine/doctrine-bundle ###
 
 ###> nelmio/cors-bundle ###
-CORS_ALLOW_ORIGIN='^https?:\/\/(localhost|127\.0\.0\.1|(www\.)?cv\.ogene\.fr|(www\.)?olivier-massot\.ogene\.fr)(:[0-9]+)?$'
+CORS_ALLOW_ORIGIN='^https?:\/\/(localhost|127\.0\.0\.1|(www\.)?cv\.ogene\.fr|(www\.)?olivier-massot\.ogene\.fr|(.*\.)?sauvagerie\.fr)(:[0-9]+)?$'
 ###< nelmio/cors-bundle ###
 
 ###> symfony/mailer ###
@@ -17,6 +17,7 @@ MAILER_DSN=smtp://127.0.0.1:25?encryption=STARTTLS&verify_peer=0
 
 FROM_EMAIL=noreply@mail.ogene.fr
 CONTACT_EMAIL=olinox14@tuta.io
+CONTACT_EMAIL_SAUVAGERIE=contact@sauvagerie.fr
 
 ###> altcha-org/altcha ###
 HMAC_KEY=eJd1VZeA9JVivlLdy6RrwUjUcs8kVRsMbILWudLC0kF3NiAl
@@ -24,4 +25,4 @@ HMAC_KEY=eJd1VZeA9JVivlLdy6RrwUjUcs8kVRsMbILWudLC0kF3NiAl
 
 ID_AGE=35
 ID_PLACE="50290 BREHAL, France"
-ID_STATUS="Civil partnership, 3 children"
+ID_STATUS="Civil partnership, 3 children"

+ 1 - 0
config/services.yaml

@@ -14,6 +14,7 @@ services:
             $projectDir: '%kernel.project_dir%'
             $fromEmail: '%env(FROM_EMAIL)%'
             $contactEmail: '%env(CONTACT_EMAIL)%'
+            $contactEmailSauvagerie: '%env(CONTACT_EMAIL_SAUVAGERIE)%'
             $hmacKey: '%env(HMAC_KEY)%'
             $idAge: '%env(ID_AGE)%'
             $idPlace: '%env(ID_PLACE)%'

+ 14 - 4
src/State/Processor/ContactRequestProcessor.php

@@ -8,6 +8,7 @@ use ApiPlatform\Metadata\Operation;
 use ApiPlatform\Metadata\Post;
 use ApiPlatform\State\ProcessorInterface;
 use App\ApiResource\ContactRequest;
+use Symfony\Component\HttpFoundation\RequestStack;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
 use Symfony\Component\Mailer\MailerInterface;
@@ -19,7 +20,9 @@ class ContactRequestProcessor implements ProcessorInterface
         private readonly MailerInterface $symfonyMailer,
         private readonly string $fromEmail,
         private readonly string $contactEmail,
-        private readonly string $hmacKey
+        private readonly string $contactEmailSauvagerie,
+        private readonly string $hmacKey,
+        private readonly RequestStack $requestStack
     )
     {}
 
@@ -49,10 +52,17 @@ class ContactRequestProcessor implements ProcessorInterface
             throw new \RuntimeException('Invalid payload');
         }
 
+        // Get the recipient parameter from the query, default to 'cv' if not provided
+        $request = $this->requestStack->getCurrentRequest();
+        $recipient = $request ? $request->query->get('recipient', 'cv') : 'cv';
+
+        // Determine the email recipient based on the recipient parameter
+        $emailTo = $recipient === 'sauvagerie' ? $this->contactEmailSauvagerie : $this->contactEmail;
+
         $symfonyMail = (new Email())
-            ->to($this->contactEmail)
+            ->to($emailTo)
             ->from($this->fromEmail)
-            ->subject('Contact from cv.ogene.fr')
+            ->subject('Contact from ' . $recipient . ' website')
             ->text(
                 'From : ' . $contactRequest->getEmail() . "\n" .
                 'Name: ' . ($contactRequest->getName() ?? '-') . "\n\n" .
@@ -63,4 +73,4 @@ class ContactRequestProcessor implements ProcessorInterface
 
         return $contactRequest;
     }
-}
+}