diff --git a/composer.lock b/composer.lock index 8c2f2851..09e6ec1b 100644 --- a/composer.lock +++ b/composer.lock @@ -699,16 +699,16 @@ }, { "name": "doctrine/dbal", - "version": "3.3.3", + "version": "3.3.4", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "82331b861727c15b1f457ef05a8729e508e7ead5" + "reference": "83f779beaea1893c0bece093ab2104c6d15a7f26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/82331b861727c15b1f457ef05a8729e508e7ead5", - "reference": "82331b861727c15b1f457ef05a8729e508e7ead5", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/83f779beaea1893c0bece093ab2104c6d15a7f26", + "reference": "83f779beaea1893c0bece093ab2104c6d15a7f26", "shasum": "" }, "require": { @@ -790,7 +790,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.3.3" + "source": "https://github.com/doctrine/dbal/tree/3.3.4" }, "funding": [ { @@ -806,7 +806,7 @@ "type": "tidelift" } ], - "time": "2022-03-09T15:39:50+00:00" + "time": "2022-03-20T18:37:29+00:00" }, { "name": "doctrine/deprecations", @@ -10310,16 +10310,16 @@ }, { "name": "twig/twig", - "version": "v2.14.11", + "version": "v2.14.12", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "66baa66f29ee30e487e05f1679903e36eb01d727" + "reference": "19c898bda30c5edea573bbb9ee1235d8cf6956ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/66baa66f29ee30e487e05f1679903e36eb01d727", - "reference": "66baa66f29ee30e487e05f1679903e36eb01d727", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/19c898bda30c5edea573bbb9ee1235d8cf6956ed", + "reference": "19c898bda30c5edea573bbb9ee1235d8cf6956ed", "shasum": "" }, "require": { @@ -10374,7 +10374,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v2.14.11" + "source": "https://github.com/twigphp/Twig/tree/v2.14.12" }, "funding": [ { @@ -10386,7 +10386,7 @@ "type": "tidelift" } ], - "time": "2022-02-04T06:57:25+00:00" + "time": "2022-03-25T09:34:52+00:00" }, { "name": "webmozart/assert", diff --git a/src/Controller/AdminEntradaController.php b/src/Controller/AdminEntradaController.php index d2a80360..1d878db1 100755 --- a/src/Controller/AdminEntradaController.php +++ b/src/Controller/AdminEntradaController.php @@ -17,6 +17,7 @@ use App\Service\UploaderHelper; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\QueryException; +use Doctrine\Persistence\ManagerRegistry; use Exception; use Knp\Component\Pager\PaginatorInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; @@ -31,16 +32,22 @@ class AdminEntradaController extends AbstractController { private LoggerClient $loggerClient; private BoleanToDateHelper $boleanToDateHelper; + private ManagerRegistry $managerRegistry; /** * NO usado es opcional. * @param LoggerClient $loggerClient * @param BoleanToDateHelper $boleanToDateHelper + * @param ManagerRegistry $managerRegistry */ - public function __construct(LoggerClient $loggerClient, BoleanToDateHelper $boleanToDateHelper) - { + public function __construct( + LoggerClient $loggerClient, + BoleanToDateHelper $boleanToDateHelper, + ManagerRegistry $managerRegistry + ) { $this->loggerClient = $loggerClient; $this->boleanToDateHelper = $boleanToDateHelper; + $this->managerRegistry = $managerRegistry; } /** @@ -51,8 +58,11 @@ public function __construct(LoggerClient $loggerClient, BoleanToDateHelper $bole * @param Request $request * @return Response */ - public function index(EntradaRepository $entradaRepository, PaginatorInterface $paginator, Request $request): Response - { + public function index( + EntradaRepository $entradaRepository, + PaginatorInterface $paginator, + Request $request + ): Response { $bus = $request->get('busq'); if ($this->isGranted('ROLE_EDITOR')) { $entrada = $entradaRepository->queryFindAllEntradas($bus); @@ -81,7 +91,8 @@ public function index(EntradaRepository $entradaRepository, PaginatorInterface $ */ public function listadoPublicado(EntradaRepository $entradaRepository): Response { - $this->isGranted('ROLE_EDITOR') ? $entrada = $entradaRepository->findAllPublicadosOrderedByPublicacion() : $entrada = $entradaRepository->findAllPublicadosOrderedByPublicacion($this->getUser()); + $this->isGranted('ROLE_EDITOR') ? $entrada = $entradaRepository->findAllPublicadosOrderedByPublicacion( + ) : $entrada = $entradaRepository->findAllPublicadosOrderedByPublicacion($this->getUser()); return $this->render('admin_entrada/list.html.twig', [ 'entradas' => $entrada, @@ -93,7 +104,6 @@ public function listadoPublicado(EntradaRepository $entradaRepository): Response * @param Entrada $entrada * @param UploaderHelper $uploaderHelper * @param ObtenerDatosHelper $datosHelper - * @param PrincipalRepository $principalRepository * @return RedirectResponse * @throws Exception * @Route("/admin/entrada/{id}/edit", name="admin_entrada_edit") @@ -103,10 +113,8 @@ public function edit( Request $request, Entrada $entrada, UploaderHelper $uploaderHelper, - ObtenerDatosHelper $datosHelper, - PrincipalRepository $principalRepository - ): Response - { + ObtenerDatosHelper $datosHelper + ): Response { $form = $this->createForm(EntradaType::class, $entrada); $form->handleRequest($request); @@ -116,7 +124,6 @@ public function edit( $boolean = $form['publicar']->getData(); $link = $form['linkRoute']->getData(); - $publicado = $this->boleanToDateHelper->setDatatimeForTrue($boolean); $entrada->setPublicadoAt($publicado); @@ -127,9 +134,9 @@ public function edit( $entrada->setImageFilename($newFilename); } - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); - $this->loggerClient->logMessage('Se editó la entrada \"' . $entrada->getTitulo() . '\"', ''); + $this->loggerClient->logMessage('Se editó la entrada \"'.$entrada->getTitulo().'\"', ''); return $this->redirectToRoute('admin_entrada_index'); } @@ -158,10 +165,8 @@ public function editComplex(Request $request, Entrada $entrada): Response $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - - $this->getDoctrine()->getManager()->flush(); - - $this->loggerClient->logMessage('Se editó la entrada \"' . $entrada->getTitulo() . '\"', ''); + $this->managerRegistry->getManager()->flush(); + $this->loggerClient->logMessage('Se editó la entrada \"'.$entrada->getTitulo().'\"', ''); return $this->redirectToRoute('admin_entrada_index'); } @@ -202,13 +207,12 @@ public function new(EntityManagerInterface $em, Request $request, UploaderHelper $titulo = $form['titulo']->getData(); - if(!$link and $titulo) { - $link = $this->limpiaLink(null,$titulo); - }else{ + if (!$link and $titulo) { + $link = $this->limpiaLink($titulo); + } else { $link = $link->getlinkRoute(); } - $entrada->setLinkRoute($link); if ($uploadedFile) { @@ -218,7 +222,6 @@ public function new(EntityManagerInterface $em, Request $request, UploaderHelper $boolean = $form['publicar']->getData(); - $publicado = $this->boleanToDateHelper->setDatatimeForTrue($boolean); $entrada->setPublicadoAt($publicado); @@ -235,6 +238,7 @@ public function new(EntityManagerInterface $em, Request $request, UploaderHelper 'entrada' => $entrada, ]); } + /** * @Route("/admin/new/step1", name="admin_entrada_new_step1", methods={"GET","POST"}) * @param Request $request @@ -251,12 +255,11 @@ public function newStepOne(Request $request): Response if ($form->isSubmitted() && $form->isValid()) { $section = $form['section']->getData(); $entrada->addSection($section); - $entityManager = $this->getDoctrine()->getManager(); - $entityManager->persist($entrada); - $entityManager->flush(); + $this->managerRegistry->getManager()->persist($entrada); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('admin_entrada_new_step2', [ - 'id' => $entrada->getId() + 'id' => $entrada->getId(), ]); } @@ -266,7 +269,6 @@ public function newStepOne(Request $request): Response ]); } - /** * @Route("/admin/new/step2/{id}", name="admin_entrada_new_step2", methods={"GET","POST"}) * @param Request $request @@ -276,16 +278,15 @@ public function newStepOne(Request $request): Response */ public function newStepTwo(Request $request, Entrada $entrada): Response { - $form = $this->createForm(StepTwoType::class, $entrada); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $this->getDoctrine()->getManager()->flush(); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('admin_entrada_new_step3', [ - 'id' => $entrada->getId() + 'id' => $entrada->getId(), ]); } @@ -311,12 +312,11 @@ public function newStepThree(Request $request): Response if ($form->isSubmitted() && $form->isValid()) { $section = $form['section']->getData(); $entrada->addSection($section); - $entityManager = $this->getDoctrine()->getManager(); - $entityManager->persist($entrada); - $entityManager->flush(); + $this->managerRegistry->getManager()->persist($entrada); + $this->managerRegistry->getManager()->flush(); return $this->redirectToRoute('admin_entrada_index', [ - 'id' => $entrada->getId() + 'id' => $entrada->getId(), ]); } @@ -326,7 +326,6 @@ public function newStepThree(Request $request): Response ]); } - /** * @Route("/admin/entrada/{linkRoute}", name="entrada_admin_link") * @@ -347,9 +346,6 @@ public function link(Entrada $entrada): Response */ public function show(Entrada $entrada): Response { - if (!$entrada) { - throw $this->createNotFoundException(sprintf('No se encontró la entrada "%s"', $entrada)); - } return $this->render('entrada/show.html.twig', [ 'entrada' => $entrada, @@ -364,40 +360,32 @@ public function show(Entrada $entrada): Response */ public function delete(Request $request, Entrada $entrada): Response { - if ($this->isCsrfTokenValid('delete' . $entrada->getId(), $request->request->get('_token'))) { - $entityManager = $this->getDoctrine()->getManager(); - $entityManager->remove($entrada); - $entityManager->flush(); + if ($this->isCsrfTokenValid('delete'.$entrada->getId(), $request->request->get('_token'))) { + $this->managerRegistry->getManager()->remove($entrada); + $this->managerRegistry->getManager()->flush(); } return $this->redirectToRoute('admin_entrada_index'); } /** - * @param null|string $link * @param string $titulo * @return string */ - private function limpiaLink(?string $link , string $titulo): string + private function limpiaLink(string $titulo): string { - if ('' != $link) { - $link = strtolower(str_replace(' ', '-', trim($link))); - } else { - $link = strtolower(str_replace(' ', '-', trim($titulo))); - $link = strtolower(str_replace('
', '', trim($link))); - $link = strtolower(str_replace('
', '', trim($link))); - } - return $link; + $link = strtolower(str_replace(' ', '-', trim($titulo))); + $link = strtolower(str_replace('', '', trim($link))); + return strtolower(str_replace('
', '', trim($link))); } - /** * @param Principal|null $principal * @return string|null */ private function getLinkRoute(?Principal $principal): ?string { - if(null === $principal){ + if (null === $principal) { return null; } return $principal->getLinkRoute(); @@ -410,7 +398,7 @@ private function getLinkRoute(?Principal $principal): ?string */ private function getPrincipal(?string $linkRoute, PrincipalRepository $principalRepository): ?Principal { - if(null === $linkRoute){ + if (null === $linkRoute) { return null; } diff --git a/src/Controller/PerfilController.php b/src/Controller/PerfilController.php index fc921106..a55ce3c2 100755 --- a/src/Controller/PerfilController.php +++ b/src/Controller/PerfilController.php @@ -2,18 +2,17 @@ namespace App\Controller; - use App\Entity\User; use App\Form\ChangePasswordType; -use App\Form\UserType; use App\Repository\IndexAlamedaRepository; -use App\Repository\UserRepository; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; - +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; -use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface; +use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface; use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; /** @@ -29,10 +28,8 @@ class PerfilController extends BaseController * @param IndexAlamedaRepository $indexAlamedaRepository * @return Response */ - public function index(IndexAlamedaRepository $indexAlamedaRepository) + public function index(IndexAlamedaRepository $indexAlamedaRepository): Response { - - return $this->render('perfil/perfil_index.html.twig', [ 'datosIndex' => $indexAlamedaRepository->findAll()[0], ]); @@ -41,7 +38,7 @@ public function index(IndexAlamedaRepository $indexAlamedaRepository) /** * @Route("/api/perfil", name="api_perfil") */ - public function apiPerfil() + public function apiPerfil(): JsonResponse { $user = $this->getUser(); @@ -54,13 +51,12 @@ public function apiPerfil() * @Route("/web/cambiopassword/{email}", name="app_changepassword") * @param Request $request * @param User $user - * @param UserPasswordEncoderInterface $passwordEncoder + * @param UserPasswordHasherInterface $passwordEncoder * @param AuthenticationUtils $authenticationUtils - * @param UserRepository $userRepository * @return Response */ - public function changePassword(Request $request, User $user, UserPasswordEncoderInterface $passwordEncoder, AuthenticationUtils $authenticationUtils, UserRepository $userRepository){ - + public function changePassword(Request $request, User $user, UserPasswordHasherInterface $passwordEncoder, AuthenticationUtils $authenticationUtils): Response + { $form = $this->createForm(ChangePasswordType::class, $user); $form->handleRequest($request); @@ -68,11 +64,14 @@ public function changePassword(Request $request, User $user, UserPasswordEncoder /** @var User $user */ $password = $form['password']->getData(); $user->setPassword( - $passwordEncoder->encodePassword($user, $password) + $passwordEncoder->hashPassword($user, $password) ); - $em = $this->getDoctrine()->getManager(); - $em->persist($user); - $em->flush(); + try { + $em = $this->container->get('doctrine')->getManager(); + $em->persist($user); + $em->flush(); + } catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) { + } $error = $authenticationUtils->getLastAuthenticationError(); $lastUsername = $authenticationUtils->getLastUsername(); @@ -83,10 +82,9 @@ public function changePassword(Request $request, User $user, UserPasswordEncoder ]); } - return $this->render('security/changepassword.html.twig',[ + return $this->render('security/change-password.html.twig',[ 'user' => $user, 'form'=>$form->createView() ]); - } } diff --git a/src/Entity/User.php b/src/Entity/User.php index b472af2f..ca611ac9 100755 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -19,7 +19,7 @@ * message="Este email ya está registrado" * ) */ -class User implements UserInterface +class User implements UserInterface, \Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface { /** * @ORM\Id() diff --git a/templates/admin_entrada/list.html.twig b/templates/admin_entrada/list.html.twig index 80c59595..0680669e 100644 --- a/templates/admin_entrada/list.html.twig +++ b/templates/admin_entrada/list.html.twig @@ -54,7 +54,7 @@':'', '
':''}) | raw | u.truncate(20, '...') }}':'', '
':''}) | raw | u.truncate(20, '...') }} -':'', '
':''}) | raw | u.truncate(20, '...') }} + +