<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
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;
use Symfony\Component\EventDispatcher\EventDispatcher;
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) {
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('homepage');
}
return $this->redirect($url);
}
return $this->redirect($this->generateUrl('login'));
}
}