<?php
namespace 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\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
{
public function __construct(private ManagerRegistry $doctrine, private LoggerInterface $logger) {}
#[Route('/login', name: 'login')]
public function login(Request $request, AuthenticationUtils $authenticationUtils, PasswordHasherFactoryInterface $hasherFactory): Response
{
$doctrine = $this->doctrine;
$logger = $this->logger;
$logger->info('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,
]
);
}
#[Route('/logout', name: 'logout')]
public function logout(Request $request): Response
{
}
}