johnykvsky /
spisywarka
| 1 | <?php |
||
| 2 | namespace App\Controller\Security; |
||
| 3 | |||
| 4 | use App\Form\Type\UserLoginType; |
||
| 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
| 6 | use Symfony\Component\Routing\Annotation\Route; |
||
| 7 | use Symfony\Component\Security\Http\Authentication\AuthenticationUtils; |
||
| 8 | use Symfony\Component\Form\FormError; |
||
| 9 | |||
| 10 | class SecurityController extends Controller |
||
|
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @Route("/login", name="login", methods={"GET", "POST"}) |
||
| 14 | */ |
||
| 15 | public function login(AuthenticationUtils $authenticationUtils) |
||
| 16 | { |
||
| 17 | $error = $authenticationUtils->getLastAuthenticationError(); |
||
| 18 | $lastUsername = $authenticationUtils->getLastUsername(); |
||
| 19 | $form = $this->createForm(UserLoginType::class); |
||
| 20 | |||
| 21 | if ($error) { |
||
| 22 | $error = new FormError("There is an error: " . $error->getMessage()); |
||
| 23 | $form->addError($error); |
||
| 24 | }; |
||
| 25 | |||
| 26 | if ($form->isSubmitted() && $form->isValid() && !$error) { |
||
| 27 | return $this->redirectToRoute('admin_dashboard'); |
||
| 28 | } |
||
| 29 | |||
| 30 | return $this->render( |
||
| 31 | 'security/login.html.twig', |
||
| 32 | [ |
||
| 33 | 'form' => $form->createView(), |
||
| 34 | 'last_username' => $lastUsername, |
||
| 35 | 'error' => $error, |
||
| 36 | ] |
||
| 37 | ); |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @Route("/logout", name="logout", methods={"GET"}) |
||
| 42 | */ |
||
| 43 | public function logout() |
||
| 44 | { |
||
| 45 | // controller can be blank: it will never be executed! |
||
| 46 | throw new \Exception('Don\'t forget to activate logout in security.yaml'); |
||
| 47 | } |
||
| 48 | } |