<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Entity\Cart;
use App\Entity\Userlog;
class LoginController extends AbstractController
{
private $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
// Accessing the session in the constructor is *NOT* recommended, since
// it might not be accessible yet or lead to unwanted side-effects
// $this->session = $requestStack->getSession();
}
/**
* @Route("/login", name="login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error, 'message' => '', 'checkout' => '0']);
}
/**
* @Route("/logout", name="logout")
*/
public function logout()
{
$session = $this->requestStack->getSession(); //$session = $this->get('session');
$placeid = $session->get('place');
$session->clear();
$session->invalidate();
return $this->redirectToRoute('homepage2', [
'placeid' => $placeid
]);
//throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
/**
* @Route("/logout2", name="logout2" , options={"expose"=true})
*/
public function logout2()
{
//clear users 'barzahlung' cart
$uid = $_POST['id'];
$session = $this->requestStack->getSession(); //$session = $this->get('session');
$placeid = $session->get('place');
$log = new Userlog();
if($uid == NULL)
{
$log->setUlUid(0);
}
else
{
$log->setUlUid( $uid);
}
$log->setUlSessionid($session->getId());
$log->setUlBrowser($_SERVER['HTTP_USER_AGENT']);
$log->setUlIp($_SERVER['REMOTE_ADDR']);
$now = new \DateTime(date("Y-m-d H:i:s"));
$log->setUlNow($now);
if($placeid == NULL)
{
$log->setUlPlace(0);
}
else
{
$log->setUlPlace($placeid);
}
$log->setUlAction(2);
$log->setUlReferer($_SERVER['HTTP_REFERER']);
$log->setUlCurrentPage($_SERVER['REQUEST_URI']);
$em = $this->getDoctrine()->getManager();
$em->persist($log);
$em->flush();
$conn = $this->getDoctrine()->getManager()->getConnection();
$query = "DELETE FROM cart WHERE ca_uid = ?";
$conn->executeQuery(
$query
,array(
$uid
)
);
return new Response('');
die();
}
}