src/Controller/SecurityController.php line 24
<?phpnamespace App\Controller;use App\Entity\Office;use App\Entity\Users;use Doctrine\Persistence\ManagerRegistry;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpFoundation\Session\Session;use Symfony\Component\HttpKernel\KernelInterface;use Symfony\Component\PasswordHasher\Hasher\MessageDigestPasswordHasher;use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Core\Security;use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;use Psr\Log\LoggerInterface;class SecurityController extends AbstractController{private string $environment;private string $sessionId = '0';public function __construct(private ManagerRegistry $doctrine, private LoggerInterface $logger) {}#[\Symfony\Component\Routing\Attribute\Route('/login', name: 'login')]public function login(KernelInterface $kernel, Request $request, AuthenticationUtils $authenticationUtils, PasswordHasherFactoryInterface $hasherFactory): Response{$this->environment = $kernel->getEnvironment();$doctrine = $this->doctrine;$logger = $this->logger;$session = $request->getSession();$this->sessionId = $session->getId();$this->logOnDev('loginAction(' . ($request->isMethod('GET') ? 'GET' : ($request->isMethod('POST') ? 'POST' : 'OTHER')) .')');$user = new Users();// $passwordHasher = $hasherFactory->getPasswordHasher($user);// $logger->info('PasswordHasher='.get_class($passwordHasher).', '.$passwordHasher->encodeHashAsBase64);// $encoder = new MessageDigestPasswordHasher('sha1', false, 1);$plainPassword = 'xieyF@jzCH@9';// $encoded = $encoder->hash($plainPassword, '956540bd03d6da0546943322f348e405');// $user->setPassword($encoded);// $logger->info('loginAction: encoded: '.$encoded);// get the login error if there is one$error = $authenticationUtils->getLastAuthenticationError();// last username entered by the user$lastUsername = $authenticationUtils->getLastUsername();$uri = $request->server->get('HTTP_HOST');$officeArray = $doctrine->getRepository(Office::class)->findByofficedomain($uri);$office = array_pop($officeArray);$officeLogo = 'london-banner.jpg';if ($office !== null)$officeLogo = $office->getSitelogo();//return new Response(var_dump($office));//die;return $this->render('security/login.html.twig',['controller_name' => 'SecurityController',// last username entered by the user'last_username' => $lastUsername,'error' => $error,'uri' => $uri,'office' => $office,'officeSiteLogo'=> $officeLogo,]);}#[\Symfony\Component\Routing\Attribute\Route('/logout', name: 'logout')]public function logout(Request $request): Response{$this->sessionId = $session->getId();$this->logOnDev($sessionId.': Logout');$session->remove('user_authenticated');}private function logOnDev($msg) {if ($this->environment === 'dev') {$this->logger->info('SecurityController:'.$this->sessionId.': '.$msg);}}}