src/Controller/SecurityController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\DBAL;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController
  10. {
  11.     #[Route(path'/login'name'app_login')]
  12.     public function login(AuthenticationUtils $authenticationUtils): Response
  13.     {
  14.         // get the login error if there is one get the login error if there is
  15.         // one get the login error if there is one get the login error if there
  16.         // is one get the login error if there is one get the login error if
  17.         // there is one
  18.         $error $authenticationUtils->getLastAuthenticationError();
  19.         if ($error) {
  20.             $this->addFlash('error'$error->getMessage());
  21.         }
  22.         return $this->render('security/login.html.twig');
  23.     }
  24.     #[Route(path'/logout'name'app_logout')]
  25.     public function logout(): void
  26.     {
  27.         $this->addFlash('success''You have been logged out.');
  28.     }
  29.     #[Route(path'/security/switch-agent'name'security.switch_agent')]
  30.     public function switchAgent(
  31.         Request $request,
  32.         DBAL\Connection $connection,
  33.     ): Response {
  34.         if (!in_array($request->getSession()->get('userstamp'), ['twalls''kswafford2''jwalker'])) {
  35.             $this->addFlash('error''You do not have permission to access this page.');
  36.             return $this->redirectToRoute('dashboard.home');
  37.         }
  38.         if ($request->isMethod('POST') && $request->request->has('profile')) {
  39.             $username $request->request->get('profile');
  40.             return $this->redirect('/?_switch_user=' $username);
  41.         }
  42.         $agents $connection->createQueryBuilder()
  43.             ->select('idagent, username, fname, lname, active')
  44.             ->from('agents')
  45.             ->orderBy('lname')
  46.             ->execute()
  47.             ->fetchAllAssociative();
  48.         return $this->render('security/switch_agent.html.twig', [
  49.             'agents' => $agents,
  50.             'current_agent_id' => $request->getSession()->get('idagent')
  51.         ]);
  52.     }
  53. }