Advertisement
n0rthway

kno-security-controller

May 30th, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppBundle\Controller;
  4.  
  5. use AppBundle\Form\LoginForm;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  7. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  8.  
  9. class SecurityController extends Controller
  10. {
  11.  
  12.     /**
  13.      * @Route("/login", name="security_login")
  14.      */
  15.     public function loginAction()
  16.     {
  17.         $authenticationUtils = $this->get('security.authentication_utils');
  18.  
  19.         // get the login error if there is one
  20.         $error = $authenticationUtils->getLastAuthenticationError();
  21.  
  22.         // last username entered by the user
  23.         $lastUsername = $authenticationUtils->getLastUsername();
  24.  
  25.         $form = $this->createForm(LoginForm::class, [
  26.             '_username' => $lastUsername
  27.         ]);
  28.  
  29.         return $this->render(
  30.             'security/login.html.twig',
  31.             array(
  32.                 'form' => $form->createView(),
  33.                 'error' => $error,
  34.             )
  35.         );
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement