I would like to create a login form available from all the website by the navbar which is on the top. By clicking on "login" it opens a dropdown with the login form. Still I don't really know how to proceed, I used a render twig function in my dropdown, I got my login form, but something went wrong.
when I failed to login, I obtain a simple vue of the login form with errors (normal), but only it, not the rest of the website, moreover tip "website/login" redirect me to this login form alone too.
My files are :
# /src/Controller/SecurityController.php
# the function into "class SecurityController extends Controller"
/** * @Route("/login", name="login") */public function loginAction(Request $request, AuthenticationUtils $authUtils){ if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { return $this->redirectToRoute('homepage'); } // get the login error if there is one $error = $authUtils->getLastAuthenticationError(); // last username entered by the user $lastUsername = $authUtils->getLastUsername(); return $this->render('security/login.html.twig', array( // last username entered by the user'last_username' => $lastUsername,'error' => $error, ) );}
The twig function used in my "navbar.html.twig" is :
{{ render(controller('App\\Controller\\SecurityController::loginAction')) }}
The "login.html.twig" look like this :
{% if error %}<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>{% endif %}<form action="{{ path("login_check") }}" method="post"><div><input type="text" required="required" id="username" name="_username" value="{{ last_username }}" placeholder="Adresse email" /></div><div><input type="password" required="required" id="password" name="_password" placeholder="Mot de passe" /></div><div><input type="checkbox" id="_remember_me" name="_remember_me" checked /><label for="_remember_me">Se souvenir de moi</label></div><div><button type="submit" name="login">Se connecter</button></div></form>
Is it possible to do what I want? (without ajax?)