<?php
namespace App\Controller;
use App\Entity\Pin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class SecurityController extends AbstractController {
/**
* @Route("/login", name="login", methods={"POST", "GET"})
*/
public function loginAction(Request $request) {
if($request->request->get('pin')) {
$postedPin = $request->request->get('pin');
if($postedPin == "S3L7MX") {
return $this->autologin('V4VU979jXj');
} else {
$this->addFlash("error", "Pin not valid!");
}
}
return $this->render('security/login.html.twig', [
'dcLoginId' => $_ENV['DOCCHECK_CLIENT_ID']
]);
}
/**
* @Route("/autologin/{auth}", name="autologin")
*/
public function autologin($auth) {
// // Turn off autologin
// if (!isset($_GET['dc']) || $_GET['dc'] != '1') {
// return $this->redirect($this->generateUrl('homepage'));
// }
// // end
$this->get('session')->remove('dcLogin');
if ($auth == "V4VU979jXj") {
if (isset($_GET['dc']) && $_GET['dc'] == '1') {
$this->get('session')->set('dcLogin', true);
}
$token = new UsernamePasswordToken("user", '$2a$12$qR7kTv6J8YvfsTDXl4drJeMO0GHkJaoxwk3VHZMKipZ3vWYgDxnfO', "main", array('ROLE_USER'));
$this->get("security.token_storage")->setToken($token); //now the user is logged in
//now dispatch the login event
$request = $this->get('request_stack')->getCurrentRequest();
$event = new InteractiveLoginEvent($request, $token);
$dispatcher = new EventDispatcher();
$dispatcher->dispatch($event);
if ($request->getSession()->get('_security.main.target_path' ) ) {
$url = $request->getSession()->get( '_security.main.target_path' );
} else {
$url = $this->generateUrl('fachbereich_home');
}
return $this->redirect($url);
}
return $this->redirect($this->generateUrl('homepage'));
}
/**
* @Route("/logout", name="app_logout", methods={"GET"})
*/
public function logout(): void
{
// controller can be blank: it will never be called!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}