webcron/src/Controller/SecurityController.php

45 lines
1.5 KiB
PHP
Raw Normal View History

2021-04-06 19:33:20 +02:00
<?php
2022-04-27 14:24:48 +02:00
namespace App\Controller;
2021-04-06 19:33:20 +02:00
2022-04-27 14:24:48 +02:00
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
2022-05-24 18:09:14 +02:00
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
2021-04-06 19:33:20 +02:00
use Symfony\Component\HttpFoundation\Response;
2022-04-27 14:24:48 +02:00
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
2021-04-06 19:33:20 +02:00
2022-04-27 14:24:48 +02:00
class SecurityController extends AbstractController
2021-04-06 19:33:20 +02:00
{
2022-05-24 18:09:14 +02:00
public function loginAction(Request $request, AuthenticationUtils $authenticationUtils): Response
2021-04-06 19:33:20 +02:00
{
if($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
2022-09-07 14:36:22 +02:00
$session = $request->getSession();
$user = $this->getUser();
$session->set('_locale', $user->getLocale());
return new RedirectResponse($this->generateUrl('job_index', ['_locale' => $user->getLocale()]));
2022-05-24 18:09:14 +02:00
}
2022-04-27 14:24:48 +02:00
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'controller_name' => 'LoginController',
'last_username' => $lastUsername,
'error' => $error
]);
2021-04-06 19:33:20 +02:00
}
2021-04-07 13:31:57 +02:00
2022-04-27 14:24:48 +02:00
public function logoutAction(): void
2021-04-09 15:14:35 +02:00
{
2022-04-27 14:24:48 +02:00
// controller can be blank: it will never be called!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
2021-04-09 15:14:35 +02:00
}
public function loginCheckAction(): void
2021-04-07 13:31:57 +02:00
{
2021-04-09 15:14:35 +02:00
2021-04-07 13:31:57 +02:00
}
2021-04-06 19:33:20 +02:00
}