Browse Source

Rememberme works !

François Drouhard 3 years ago
parent
commit
3b822dddac

+ 0 - 1
config/packages/security.yaml

@@ -31,7 +31,6 @@ security:
             #        - App\Security\LoginFormAuthenticator
             remember_me:
                 secret: '%kernel.secret%'
-                lifetime: 2592000
             logout:
                 path: app_logout
                 target: app_login

+ 7 - 0
src/Security/LoginFormAuthenticator.php

@@ -11,6 +11,7 @@ use Symfony\Component\Security\Core\Security;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Security\Http\Authenticator\AbstractLoginFormAuthenticator;
 use Symfony\Component\Security\Http\Authenticator\Passport\Badge\CsrfTokenBadge;
+use Symfony\Component\Security\Http\Authenticator\Passport\Badge\RememberMeBadge;
 use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
 use Symfony\Component\Security\Http\Authenticator\Passport\Credentials\PasswordCredentials;
 use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
@@ -55,6 +56,7 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
             new PasswordCredentials($request->request->get('password', '')),
             [
                 new CsrfTokenBadge('authenticate', $request->get('_csrf_token')),
+                new RememberMeBadge(),
             ]
         );
     }
@@ -80,4 +82,9 @@ class LoginFormAuthenticator extends AbstractLoginFormAuthenticator
     {
         return $this->urlGenerator->generate(self::LOGIN_ROUTE);
     }
+
+    public function supportsRememberMe(): bool
+    {
+        return true;
+    }
 }

+ 2 - 3
templates/security/login.html.twig

@@ -28,9 +28,8 @@
                         See https://symfony.com/doc/current/security/remember_me.html
                     #}
                         <div class="checkbox mb-3">
-                            <label>
-                                <input type="checkbox" name="_remember_me"> Se souvenir de moi
-                            </label>
+                            <input type="checkbox" name="_remember_me">
+                            <label for="remember_me">Se souvenir de moi</label>
                         </div>