src/Controller/Security/LoginController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Security;
  3. use App\Form\EditUserType;
  4. use App\Service\OrderService;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Core\Security;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. /**
  13. * @Route("/kundenkonto")
  14. */
  15. class LoginController extends AbstractController {
  16. /** @var EntityManagerInterface */
  17. private EntityManagerInterface $entityManager;
  18. public function __construct(EntityManagerInterface $entityManager) {
  19. $this->entityManager = $entityManager;
  20. }
  21. /**
  22. * @Route("/login", name="storefront_login")
  23. */
  24. public function loginIndexAction(AuthenticationUtils $authenticationUtils, Request $request, Security $security): Response {
  25. $error = $authenticationUtils->getLastAuthenticationError();
  26. $lastUsername = $authenticationUtils->getLastUsername();
  27. $targetPath = $request->getSession()->get('_security.storefront.target_path');
  28. return $this->render('security/login.html.twig', [
  29. 'last_username' => $lastUsername,
  30. 'error' => $error,
  31. 'remember_me_enabled' => true,
  32. 'remember_me_parameter' => '_remember_me',
  33. 'remember_me_checked' => true,
  34. 'remember_me_label' => 'Angemeldet bleiben',
  35. 'is_during_checkout' => $targetPath ? true : false,
  36. ]);
  37. }
  38. /**
  39. * @Route("/logout", name="app_logout", methods={"GET"})
  40. */
  41. public function logoutIndexAction(): void {
  42. throw new \Exception('Don\'t forget to activate logout in security.yaml');
  43. }
  44. /**
  45. * @Route(
  46. * "/uebersicht",
  47. * name="customer_account_index"
  48. * )
  49. */
  50. public function customerAccountIndexAction(): Response {
  51. return $this->render('security/customer_account/index.html.twig');
  52. }
  53. /**
  54. * @Route(
  55. * "/meine-daten",
  56. * name="customer_account_profile_edit"
  57. * )
  58. */
  59. public function customerAccountEditProfileAction(Request $request): Response {
  60. $user = $this->getUser();
  61. $form = $this->createForm(EditUserType::class, $this->getUser());
  62. $form->handleRequest($request);
  63. if ($form->isSubmitted() && $form->isValid()) {
  64. $user = $this->getUser();
  65. /** @phpstan-ignore-next-line */
  66. $this->entityManager->persist($user);
  67. $this->entityManager->flush();
  68. return $this->redirectToRoute('customer_account_profile_edit');
  69. }
  70. return $this->render('security/customer_account/profile/edit.html.twig', [
  71. 'form' => $form->createView(),
  72. 'user' => $user,
  73. ]);
  74. }
  75. /**
  76. * @Route(
  77. * "/bestellungen/uebersicht",
  78. * name="customer_account_orders_index"
  79. * )
  80. */
  81. public function customerAccountOrdersIndexAction(OrderService $orderService): Response {
  82. $orders = $orderService->fetchOrders();
  83. return $this->render('security/customer_account/orders/index.html.twig', [
  84. 'orders' => $orders,
  85. ]);
  86. }
  87. /**
  88. * @Route(
  89. * "/kim-mail/uebersicht",
  90. * name="customer_account_kim_mail_index"
  91. * )
  92. */
  93. public function customerAccountKimMailIndexAction(OrderService $orderService): Response {
  94. $orders = $orderService->fetchOrders();
  95. $user = $this->getUser();
  96. $kimEmails = [];
  97. foreach ($orders as $order) {
  98. if ($order->getStatus() == 3) {
  99. $cart = $order->getShoppingCart();
  100. $items = $cart->getItems();
  101. foreach ($items as $item) {
  102. if ($item['kimAddresses']) {
  103. foreach ($item['kimAddresses'] as $kimAddress) {
  104. $kimEmails[] = $kimAddress['address'] . '' . $kimAddress['domain'];
  105. }
  106. }
  107. }
  108. }
  109. }
  110. return $this->render('security/customer_account/kim_mail/index.html.twig', [
  111. 'kimEmails' => $kimEmails,
  112. 'user' => $user,
  113. ]);
  114. }
  115. }