Skip to content
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

Use remember me field in login Symfony Form #2038

Merged
merged 2 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion assets/scss/layout/_login.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}

.login__login-form {
.form-check-label {
label[for='login_remember_me'] {
font-weight: 400;
}
}
Expand Down
1 change: 1 addition & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ security:
remember_me:
secret: '%kernel.secret%'
lifetime: 2592000
remember_me_parameter: login[remember_me]

access_control:
# this is a catch-all for the admin area
Expand Down
4 changes: 4 additions & 0 deletions src/Form/LoginType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Cocur\Slugify\Slugify;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down Expand Up @@ -58,6 +59,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'attr' => [
'placeholder' => 'placeholder.password',
],
])->add('remember_me', CheckboxType::class, [
'label' => 'label.rememberme',
'required' => false,
]);
}

Expand Down
5 changes: 1 addition & 4 deletions templates/security/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@
{{ form_start(loginForm, {'attr': {'id': 'login-form'}}) }}
{{ form_row(loginForm.username) }}
{{ form_row(loginForm.password) }}
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" name="_remember_me" id="_remember_me">
<label class="form-check-label" for="_remember_me">{{ 'label.rememberme'|trans }}</label>
</div>
{{ form_row(loginForm.remember_me) }}
<button class="btn btn-primary" type="submit">
<i class="fas fa-sign-in-alt" aria-hidden="true"></i>
{{- 'action.log_in'|trans -}}
Expand Down