src/Controller/Email.php line 45

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Testimony;
  4. use App\Repository\LessonRepository;
  5. use App\Repository\TestimonyRepository;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Google\Client;
  8. use Google\Service\Oauth2;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class Email extends AbstractController
  13. {
  14.     public function google(
  15.         Request $request
  16.     ) {
  17.         $client = new Client();
  18.         $client->setClientId("870305634351-esv1qf645qa5tsllgivul9kebktbbgdp.apps.googleusercontent.com");
  19.         $client->setClientSecret("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");
  20.         $client->setRedirectUri("https://coach.lndo.site/google");
  21.         $client->addScope("email");
  22.         $client->addScope("profile");
  23.         if ($request->get('code')) {
  24.             $token $client->fetchAccessTokenWithAuthCode($_GET['code']);
  25.             $client->setAccessToken($token['access_token']);
  26.             // get profile info
  27.             // now you can use this profile info to create account in your website and make user logged in.
  28.         }
  29.         return $this->render("emails/index.html.twig", [
  30.             "items" => [],
  31.             "google" => $client->createAuthUrl()
  32.         ]);
  33.     }
  34.     #[Route("/"name"default")]
  35.     public function index(
  36.     )
  37.     {
  38.         return $this->redirectToRoute("admin_app_login");
  39.         $items = [];
  40.         $path dirname(__DIR__,
  41.                 2) . "/templates/emails";
  42.         foreach (scandir($path) as $file) {
  43.             if (!in_array($file,
  44.                     [
  45.                         ".",
  46.                         "..",
  47.                         ".DS_STORE"
  48.                     ]) && is_file($path "/" $file)) {
  49.                 $items[] = "emails/" $file;
  50.             } else {
  51.                 foreach (scandir($path "/" $file) as $child) {
  52.                     if (!in_array($file,
  53.                             [
  54.                                 ".",
  55.                                 "..",
  56.                                 ".DS_STORE"
  57.                             ]) && is_file($path "/" $file "/" $child)) {
  58.                         $items[] = "emails/" $file "/" $child;
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.         return $this->render("emails/index.html.twig",
  64.             ["items" => $items]);
  65.     }
  66.     public function email(
  67.         Request $requestLessonRepository $lessonRepositoryTestimonyRepository $testimonyRepositoryEntityManagerInterface $entityManager
  68.     ) {
  69.         return $this->render($request->query->get("path"),
  70.             [
  71.                 "title" => "title",
  72.                 "client" => true,
  73.                 "lesson" => $lessonRepository->find(1)
  74.             ]);
  75.     }
  76. }