src/Core/Controller/Web/HomepageController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Core\Controller\Web;
  3. use App\Core\Controller\Api\HomepageApiController;
  4. use App\Core\Entity\Categoria;
  5. use App\Core\Entity\Curso;
  6. use App\Core\Entity\User;
  7. use App\Core\Repository\CategoriaRepository;
  8. use App\Core\Repository\CursoRepository;
  9. use App\Core\Repository\RecordatorioAgendaRepository;
  10. use App\Repository\TareasCursoRepository;
  11. use Knp\Component\Pager\PaginatorInterface;
  12. use Lexik\Bundle\JWTAuthenticationBundle\Encoder\JWTEncoderInterface;
  13. use Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider\JWSProviderInterface;
  14. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\Cookie;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\Mailer\MailerInterface;
  22. use Symfony\Component\Mercure\PublisherInterface;
  23. use Symfony\Component\Mercure\Update;
  24. use Symfony\Component\Mime\Address;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  28. use Symfony\Component\Serializer\SerializerInterface;
  29. class HomepageController extends AbstractController
  30. {
  31. #[Route('/', name: 'app_homepage')]
  32. function homepage(Request $request, JWTEncoderInterface $JWTEncoder, AuthenticationUtils $authenticationUtils, UrlGeneratorInterface $urlGenerator) {
  33. //Me aseguro que el login sea en https en el servidor...
  34. $strHostName = $request->getHttpHost();
  35. if ($_ENV['APP_ENV'] === 'prod') {
  36. $tieneWWW = strpos($strHostName, 'www');
  37. if ($tieneWWW === false) {
  38. $strURL = "www.{$strHostName}";
  39. return new RedirectResponse("https://{$strURL}");
  40. }
  41. if (!$request->isSecure()) {
  42. $strURL = "https://{$strHostName}";
  43. return new RedirectResponse("{$strURL}");
  44. }
  45. }
  46. else if ($_ENV['APP_ENV'] === 'test') {
  47. if (!$request->isSecure()) {
  48. $strURL = "https://{$strHostName}";
  49. return new RedirectResponse("{$strURL}");
  50. }
  51. }
  52. if ($this->getUser()) {
  53. $redirectResponse = new RedirectResponse($urlGenerator->generate('app_perfil'));
  54. $uat = [
  55. 'id' => $this->getUser()->getId(),
  56. 'idMaestro' => ($this->getUser()->getMaestro()) ? $this->getUser()->getMaestro()->getId() : 0,
  57. 'idEstudiante' => ($this->getUser()->getEstudiante()) ? $this->getUser()->getEstudiante()->getId() : 0,
  58. 'autorizado' => true];
  59. $redirectResponse->headers->setCookie(Cookie::create('UAT',$JWTEncoder->encode($uat)));
  60. return $redirectResponse;
  61. }
  62. return $this->render('homepage/homepage.html.twig');
  63. }
  64. /*
  65. * #[Route('/.well-known/assetlinks.json', name: 'app_wellknown_assetlinks')]
  66. */
  67. /*
  68. function wellKnownAssetsLinks(Request $request): JsonResponse
  69. {
  70. $asset_link_json = [[
  71. "relation" => ["delegate_permission/common.handle_all_urls"],
  72. "target" => [
  73. "namespace"=> "android_app",
  74. "package_name"=> "com.koleyo.koleyo",
  75. "sha256_cert_fingerprints" => [""]
  76. ]
  77. ]];
  78. return new JsonResponse($asset_link_json);
  79. }
  80. */
  81. #[Route('/cursos', name: 'app_homepage_cursos')]
  82. function cursosDisponibles(PaginatorInterface $paginator, CursoRepository $cursoRepository, CategoriaRepository $categoriaRepository, Request $request) {
  83. $datos = HomepageApiController::obtenerCursos($paginator, $cursoRepository, $categoriaRepository, $request, $this->getUser());
  84. return $this->render('homepage/cursos.html.twig', $datos);
  85. }
  86. }