<?php
namespace App\Controller\Security;
use App\Form\EditUserType;
use App\Service\OrderService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
/**
* @Route("/kundenkonto")
*/
class LoginController extends AbstractController {
/** @var EntityManagerInterface */
private EntityManagerInterface $entityManager;
public function __construct(EntityManagerInterface $entityManager) {
$this->entityManager = $entityManager;
}
/**
* @Route("/login", name="storefront_login")
*/
public function loginIndexAction(AuthenticationUtils $authenticationUtils, Request $request, Security $security): Response {
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
$targetPath = $request->getSession()->get('_security.storefront.target_path');
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'remember_me_enabled' => true,
'remember_me_parameter' => '_remember_me',
'remember_me_checked' => true,
'remember_me_label' => 'Angemeldet bleiben',
'is_during_checkout' => $targetPath ? true : false,
]);
}
/**
* @Route("/logout", name="app_logout", methods={"GET"})
*/
public function logoutIndexAction(): void {
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
/**
* @Route(
* "/uebersicht",
* name="customer_account_index"
* )
*/
public function customerAccountIndexAction(): Response {
return $this->render('security/customer_account/index.html.twig');
}
/**
* @Route(
* "/meine-daten",
* name="customer_account_profile_edit"
* )
*/
public function customerAccountEditProfileAction(Request $request): Response {
$user = $this->getUser();
$form = $this->createForm(EditUserType::class, $this->getUser());
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$user = $this->getUser();
/** @phpstan-ignore-next-line */
$this->entityManager->persist($user);
$this->entityManager->flush();
return $this->redirectToRoute('customer_account_profile_edit');
}
return $this->render('security/customer_account/profile/edit.html.twig', [
'form' => $form->createView(),
'user' => $user,
]);
}
/**
* @Route(
* "/bestellungen/uebersicht",
* name="customer_account_orders_index"
* )
*/
public function customerAccountOrdersIndexAction(OrderService $orderService): Response {
$orders = $orderService->fetchOrders();
return $this->render('security/customer_account/orders/index.html.twig', [
'orders' => $orders,
]);
}
/**
* @Route(
* "/kim-mail/uebersicht",
* name="customer_account_kim_mail_index"
* )
*/
public function customerAccountKimMailIndexAction(OrderService $orderService): Response {
$orders = $orderService->fetchOrders();
$user = $this->getUser();
$kimEmails = [];
foreach ($orders as $order) {
if ($order->getStatus() == 3) {
$cart = $order->getShoppingCart();
$items = $cart->getItems();
foreach ($items as $item) {
if ($item['kimAddresses']) {
foreach ($item['kimAddresses'] as $kimAddress) {
$kimEmails[] = $kimAddress['address'] . '' . $kimAddress['domain'];
}
}
}
}
}
return $this->render('security/customer_account/kim_mail/index.html.twig', [
'kimEmails' => $kimEmails,
'user' => $user,
]);
}
}