<?php
namespace App\Controller;
use App\Controller\AppController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Service\ApiCalls;
use App\Security\AppAuthenticator;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use App\Security\PasscodeAuthenticator;
class SigninController extends AppController
{
public function index(Request $Http, ApiCalls $ApiCalls, AuthenticationUtils $authenticationUtils, PasscodeAuthenticator $PasscodeAuthenticator, $state=NULL): Response
{
$check = $this->commonCalls(['getFooter','getHomeNav','getSearch']);
if(!$check){
return $check;
}
if($this->RedirectHandle!==NULL){
return $this->RedirectHandle;
}
$redirectTo = 'index';
if($state!==NULL){
$this->setData('state', $state);
}
if(!$this->getUser()){
$error = $authenticationUtils->getLastAuthenticationError();
if($error !==NULL){
$this->setData('authError', $error['message']);
}
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
$this->setData('last_username', $lastUsername);
if($this->getUser()===NULL){
return $this->render('signin/index.html.twig',
$this->getData()
);
}
else{
return $this->redirectToRoute($redirectTo);
}
}
else{
return $this->redirectToRoute($redirectTo);
}
}
public function isSignedIn(){
if(!$this->getUser()){
$response = new JsonResponse(['isSignedIn' => FALSE]);
}
else{
$response = new JsonResponse(['isSignedIn' => TRUE]);
}
return $response;
}
}