<?php
namespace App\Controller;
use Doctrine\DBAL;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
#[Route(path: '/login', name: 'app_login')]
public function login(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one get the login error if there is
// one get the login error if there is one get the login error if there
// is one get the login error if there is one get the login error if
// there is one
$error = $authenticationUtils->getLastAuthenticationError();
if ($error) {
$this->addFlash('error', $error->getMessage());
}
return $this->render('security/login.html.twig');
}
#[Route(path: '/logout', name: 'app_logout')]
public function logout(): void
{
$this->addFlash('success', 'You have been logged out.');
}
#[Route(path: '/security/switch-agent', name: 'security.switch_agent')]
public function switchAgent(
Request $request,
DBAL\Connection $connection,
): Response {
if (!in_array($request->getSession()->get('userstamp'), ['twalls', 'kswafford2', 'jwalker'])) {
$this->addFlash('error', 'You do not have permission to access this page.');
return $this->redirectToRoute('dashboard.home');
}
if ($request->isMethod('POST') && $request->request->has('profile')) {
$username = $request->request->get('profile');
return $this->redirect('/?_switch_user=' . $username);
}
$agents = $connection->createQueryBuilder()
->select('idagent, username, fname, lname, active')
->from('agents')
->orderBy('lname')
->execute()
->fetchAllAssociative();
return $this->render('security/switch_agent.html.twig', [
'agents' => $agents,
'current_agent_id' => $request->getSession()->get('idagent')
]);
}
}