src/Controller/SecurityController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Security\UserProvider;
  4. use App\Service\ProfileLoader;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. class SecurityController extends AbstractController {
  10.     /**
  11.      * @var ProfileLoader
  12.      */
  13.     private $profileLoader;
  14.     /**
  15.      * @var UserProvider
  16.      */
  17.     private $userProvider;
  18.     /**
  19.      * SecurityController constructor.
  20.      * @param ProfileLoader $profileLoader
  21.      * @param UserProvider $userProvider
  22.      */
  23.     public function __construct(ProfileLoader $profileLoaderUserProvider $userProvider) {
  24.         $this->profileLoader $profileLoader;
  25.         $this->userProvider $userProvider;
  26.     }
  27.     public function login(Request $requestAuthenticationUtils $authenticationUtils): Response {
  28. //        throw new \Exception("Nessuno profilo configurato");
  29.         
  30.         if ($this->getUser()) {
  31.             return $this->redirectToRoute('index');
  32.         }
  33.         if ($request->get("ac")) {
  34.             $ref $request->headers->get('referer');
  35.             if ($this->profileLoader->isRefererInternal($ref)) {
  36.                 $this->userProvider->loginFromToken($request->get("ac"), $request);
  37.                 return $this->redirectToRoute("index");
  38.             }
  39.             return $this->redirectToRoute("login");
  40.         }
  41.         $profiles $this->profileLoader->getAvailableProfiles();
  42.         if (empty($profiles)) {
  43.             throw new \Exception("Nessuno profilo configurato");
  44.         }
  45.         // get the login error if there is one
  46.         $error $authenticationUtils->getLastAuthenticationError();
  47.         // last username entered by the user
  48.         $lastUsername $authenticationUtils->getLastUsername();
  49.         return $this->render('login.html.twig', [
  50.             'last_username' => $lastUsername,
  51.             'last_profile' => $this->get('session')->get("profileDb"),
  52.             'error' => isset($error) ? $error->getMessage() : null,
  53.             'profiles' => $profiles,
  54.             'page' => "login",
  55.         ]);
  56.     }
  57.     public function logout() {
  58.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  59.     }
  60.     public function systemOk(Request $request) {
  61.         return new Response(true);
  62.     }
  63. }