<?php
namespace App\Controller;
use App\Entity\AccountingFirm;
use App\Entity\MailjetApi;
use App\Entity\PipelineIdentiteVisuelle;
use App\Entity\StakeholderCategory;
use App\Entity\StakeholderSubscriptionType;
use App\Entity\UsefulLink;
use App\Entity\User;
use App\Repository\AccountingFirmRepository;
use App\Repository\EmailBlacklistRepository;
use App\Repository\MailingCommunicationRepository;
use App\Repository\MailjetApiRepository;
use App\Repository\MailjetApiTypeRepository;
use App\Repository\PipelineIdentiteVisuelleRepository;
use App\Repository\StakeholderRepository;
use App\Repository\UserRepository;
use App\Services\HelpersFirmsService;
use App\Services\LagenceExpertService;
use App\Services\Mailing;
use App\Services\MailjetApiEncryptionService;
use App\Services\MailjetService;
use App\Services\TrelloService;
use Doctrine\ORM\EntityManagerInterface;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use Qferrer\Mjml\Twig\MjmlExtension;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Filesystem\Filesystem;
use Twig\Environment;
class AppController extends AbstractController
{
#[Route(name: 'app_home')]
public function index(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$changemdp = $this->getUser()->getActivationToken();
if (is_null($this->getUser()->getAccountingFirm()) && is_null($this->getUser()->getAffiliate()) && !in_array("ROLE_ADMIN", $this->getUser()->getRoles())) {
return $this->redirectToRoute('actuality_dashboard');
}
if ($this->getUser()->getAffiliate()) {
return $this->redirectToRoute('app_affiliate_request');
}
return $this->redirectToRoute('app_dashboard');
return $this->render('app/index.html.twig', [
'controller_name' => 'AppController',
'mdp' => $changemdp,
]);
}
#[IsGranted('ROLE_USER')]
#[Route(path: '/firstConnectionYes', name: 'ActivationTokenY', methods: ['GET', 'POST'])]
public function ActivationTokenY(EntityManagerInterface $em): Response
{
$user = $this->getUser();
$user->setActivationToken(true);
$em->flush();
return $this->redirectToRoute('app_forgot_password_request');
}
#[IsGranted('ROLE_USER')]
#[Route(path: '/firstConnectionNo', name: 'ActivationTokenN', methods: ['GET', 'POST'])]
public function ActivationTokenN(EntityManagerInterface $em): Response
{
$user = $this->getUser();
$user->setActivationToken(true);
$em->flush();
return $this->redirectToRoute('app_home');
}
#[Route(path: '/script-crypt-api-key', name: 'script-crypt-api-key', methods: ['GET', 'POST'])]
public function scriptCryptApiKey(EntityManagerInterface $em, MailjetApiTypeRepository $apiTypeRepository, MailjetApiRepository $mailjetApiRepository, MailjetApiEncryptionService $mailjetApiEncryptionService): Response
{
$mailjetApis = $mailjetApiRepository->findAll();
foreach ($mailjetApis as $mailjetApi) {
$mailjetApiEncryptionService->encryptMailjetApi($mailjetApi);
$em->persist($mailjetApi);
}
$em->flush();
return $this->redirectToRoute('app_home');
}
#[Route(path: '/script-crypt-api-key/{id}', name: 'script-crypt-api-key-one', methods: ['GET', 'POST'])]
public function scriptCryptApiKeyOne(string $id, EntityManagerInterface $em, MailjetApiRepository $mailjetApiRepository, MailjetApiEncryptionService $mailjetApiEncryptionService): Response
{
$mailjetApi = $mailjetApiRepository->findOneBy(['id' => $id]);
$mailjetApiEncryptionService->encryptMailjetApi($mailjetApi);
$em->persist($mailjetApi);
$em->flush();
return $this->redirectToRoute('app_home');
}
#[Route(path: '/test-files-aides', name: 'test-files-aides', methods: ['GET', 'POST'])]
public function TestFilesAides(HelpersFirmsService $helpersFirmsService): Response
{
return $this->redirectToRoute('app_home');
}
#[Route(path: '/robots.txt', name: 'robots', methods: ['GET'])]
public function robots(): Response
{
$response = new Response(
"User-agent: *\nAllow: /",
Response::HTTP_OK,
['content-type' => 'text/plain']
);
return $response;
}
#[Route(path: '/test', name: 'test', methods: ['GET', 'POST'])]
public function test(StakeholderRepository $stakeholderRepository, AccountingFirmRepository $accountingFirmRepository): Response
{
$stakeholders = $stakeholderRepository->findBySubscriptionType(
$accountingFirmRepository->find(167),
StakeholderCategory::CUSTOMER_SLUG,
StakeholderSubscriptionType::NEWSLETTER
);
$found = array_filter($stakeholders, fn($s) => strtolower($s->getEmail()) === '1mmo.armelleauguste@gmail.com');
dd(array_values($found));
}
#[Route('/nlpreview/{cabinet}', name: 'app_nlpreview')]
public function newsletterPreview(AccountingFirm $cabinet, Mailing $mailing, MjmlExtension $mjmlRenderer, Environment $twig): Response
{
$templateParams = $mailing->getNewsletterCabinetTemplateParams($cabinet, true);
return new Response($mjmlRenderer->render($twig->render('mjml/newsletter-cabinet-template.mjml', $templateParams)));
}
#[Route(path: '/get-audio-ausha', name: 'w_podcast_get_audio_ausha')]
public function getAudioAusha(Request $request)
{
$aushaId = $request->query->get('aushaid');
$aushaToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiZjkyM2U5ZmE0NzczYWVlYTE0NThmZWFiYjYzNWE3MWUxYTc5YTM2MmVjMjU3MjFhYTNlMzc4MDg4YWRkMTUyYjU2N2I0NjhjNjQwMmE1YWQiLCJpYXQiOjE3NTI2OTYwNTQuODEzMDc3LCJuYmYiOjE3NTI2OTYwNTQuODEzMDgzLCJleHAiOjIwNjgyNjU1NzQuODAxNDE1LCJzdWIiOiIxMTMwNzEiLCJzY29wZXMiOlsic2hvd3MuaW5kZXhXaXRoR3JhbnRlZCIsInNob3dzLnNob3ciLCJzaG93cy5zaG93LmJ5X3B1YmxpY2lkIiwicGxheWxpc3RzLmluZGV4IiwicGxheWxpc3RzLnN0b3JlIiwicGxheWxpc3RzLnNob3ciLCJwbGF5bGlzdHMudXBkYXRlIiwicGxheWxpc3RzLmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5zdG9yZSIsInBsYXlsaXN0cy5wb2RjYXN0LmRlc3Ryb3kiLCJwbGF5bGlzdHMucG9kY2FzdC5tb3ZlIiwicGxheWxpc3RzLmltYWdlLnN0b3JlI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KR2N1eNDvDFHTW0vVJkqnVmseF0d6RUCWp-01g7Yw6GT6QBJ-fN8-9R8MsZcyNa54W1sA7ptas2JHo3oCa_VBO_ku9aq4SLTxyjxKosr6GFxPrJMH2SfRq11VuAvb-mOPKvY5_gqe6Z_aWYbd0XuQ0uHHTtnr01u9xxAnVQdEKUUvha_LBuA9xbTjy8cAmYxgiMf5GYO4jeiikqPXlgRASVPFV6-IREYvMAqQFIDNgXnNLfn1-xbXpBtmR0Bb8IzDLqc";
$client = new Client(['base_uri' => 'https://developers.ausha.co/v1/podcasts/']);
$headers = [
'Authorization' => 'Bearer ' . $aushaToken,
'accept' => 'application/json',
'content-type' => 'application/json',
];
$ausha_mp3 = null;
try {
$response = $client->request('GET', $aushaId, [
'headers' => $headers
]);
dd($response);
$ausha = json_decode($response->getBody()->getContents());
if ($ausha->data->audio_url) {
$ausha_mp3 = $ausha->data->audio_url;
}
} catch (\Exception $e) {
dd($e);
}
return new JsonResponse([
'ausha_mp3' => $ausha_mp3
]);
}
#[IsGranted('ROLE_ADMIN')]
#[Route(path: '/test-chatbot', name: 'testChatbot', methods: ['GET', 'POST'])]
public function testChatbot(): Response
{
return $this->render('app/chatbot.html.twig', [
'controller_name' => 'AppController',
]);
}
}