src/Controller/LoginController.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  7. use Symfony\Component\HttpFoundation\RequestStack;
  8. use App\Entity\Cart;
  9. use App\Entity\Userlog;
  10. class LoginController extends AbstractController
  11. {
  12.     private $requestStack;
  13.     public function __construct(RequestStack $requestStack)
  14.     {
  15.         $this->requestStack $requestStack;
  16.         // Accessing the session in the constructor is *NOT* recommended, since
  17.         // it might not be accessible yet or lead to unwanted side-effects
  18.         // $this->session = $requestStack->getSession();
  19.     }
  20.     
  21.     /**
  22.      * @Route("/login", name="login")
  23.      */
  24.     public function login(AuthenticationUtils $authenticationUtils): Response
  25.     {
  26.         // if ($this->getUser()) {
  27.         //     return $this->redirectToRoute('target_path');
  28.         // }
  29.         // get the login error if there is one
  30.         $error $authenticationUtils->getLastAuthenticationError();
  31.         // last username entered by the user
  32.         $lastUsername $authenticationUtils->getLastUsername();
  33.         
  34.        
  35.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error'message' => '''checkout' => '0']);
  36.     }
  37.     /**
  38.      * @Route("/logout", name="logout")
  39.      */
  40.     public function logout()
  41.     {
  42.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  43.         $placeid $session->get('place');
  44.         $session->clear();
  45.         $session->invalidate();
  46.         return $this->redirectToRoute('homepage2', [
  47.             'placeid' => $placeid
  48.         ]);
  49.         //throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  50.     }
  51.     /**
  52.      * @Route("/logout2", name="logout2" , options={"expose"=true})
  53.      */
  54.     public function logout2()
  55.     {
  56.         //clear users 'barzahlung' cart
  57.         $uid $_POST['id'];
  58.         
  59.         $session $this->requestStack->getSession(); //$session = $this->get('session');
  60.         $placeid $session->get('place');
  61.         $log = new Userlog();
  62.         if($uid == NULL)
  63.         {
  64.             $log->setUlUid(0);
  65.         }
  66.         else
  67.         {
  68.             $log->setUlUid$uid);
  69.         }
  70.         $log->setUlSessionid($session->getId());
  71.         $log->setUlBrowser($_SERVER['HTTP_USER_AGENT']);
  72.         $log->setUlIp($_SERVER['REMOTE_ADDR']);
  73.         
  74.         $now = new \DateTime(date("Y-m-d H:i:s"));
  75.         $log->setUlNow($now);
  76.         if($placeid == NULL)
  77.         {
  78.             $log->setUlPlace(0);
  79.         }
  80.         else
  81.         {
  82.             $log->setUlPlace($placeid);
  83.         }
  84.         $log->setUlAction(2);
  85.         $log->setUlReferer($_SERVER['HTTP_REFERER']);
  86.         $log->setUlCurrentPage($_SERVER['REQUEST_URI']);
  87.         $em $this->getDoctrine()->getManager();
  88.         $em->persist($log);
  89.         $em->flush();
  90.         $conn $this->getDoctrine()->getManager()->getConnection();
  91.         $query "DELETE FROM cart WHERE  ca_uid = ?";
  92.         
  93.         $conn->executeQuery(
  94.             $query
  95.             ,array(
  96.                 $uid
  97.             )
  98.          );
  99.         return new Response('');
  100.         die();
  101.     }
  102. }