Skip to content

Security: How to Build a Login Form: sync with recent Maker Bundle changes #12802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions security/form_login_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ class that processes the login submit and 4) updates the main security config fi
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();

return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error
]);
return $this->render('security/login.html.twig', ['last_username' => $lastUsername, 'error' => $error]);
}

/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \Exception('This method can be blank - it will be intercepted by the logout key on your firewall');
}

/**
Expand Down Expand Up @@ -165,10 +170,10 @@ a traditional HTML form that submits to ``/login``:
{% endif %}

<h1 class="h3 mb-3 font-weight-normal">Please sign in</h1>
<label for="inputEmail" class="sr-only">Email</label>
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" placeholder="Email" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="inputEmail">Email</label>
<input type="email" value="{{ last_username }}" name="email" id="inputEmail" class="form-control" required autofocus>
<label for="inputPassword">Password</label>
<input type="password" name="password" id="inputPassword" class="form-control" required>

<input type="hidden" name="_csrf_token"
value="{{ csrf_token('authenticate') }}"
Expand Down Expand Up @@ -300,7 +305,7 @@ a traditional HTML form that submits to ``/login``:
}
}

**Step 4.** Updates the main security config file to enable the Guard authenticator:
**Step 4.** Updates the main security config file to enable the Guard authenticator and configure logout route:

.. configuration-block::

Expand All @@ -316,6 +321,8 @@ a traditional HTML form that submits to ``/login``:
guard:
authenticators:
- App\Security\LoginFormAuthenticator
logout:
path: app_logout

.. code-block:: xml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML and PHP config blocks should be updated as well, but I'm not sure about the correct syntax as I'm not using them

Expand Down