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

👌 IMPROVE: Mise en place du cookie RememberMe #31

Merged
merged 1 commit into from
Aug 27, 2023
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
4 changes: 3 additions & 1 deletion backend/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ security:
custom_authenticator: App\Security\LoginAuthenticator
logout:
path: app_logout
# where to redirect after logout
target: app_login
remember_me:
secret: '%kernel.secret%'
lifetime: 604800 # 1 week in seconds

# activate different ways to authenticate
# https://symfony.com/doc/current/security.html#the-firewall
Expand Down
2 changes: 2 additions & 0 deletions backend/src/Security/LoginAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
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;
Expand All @@ -35,6 +36,7 @@ public function authenticate(Request $request): Passport
new UserBadge(userIdentifier: (string) $email),
credentials: new PasswordCredentials(password: (string) $request->request->get(key: 'password', default: '')),
badges: [
new rememberMeBadge(),
new CsrfTokenBadge(csrfTokenId: 'authenticate', csrfToken: (string) $request->request->get(key: '_csrf_token')),
]
);
Expand Down
12 changes: 1 addition & 11 deletions backend/templates/security/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

<div class="d-flex flex-wrap align-items-center justify-content-between pb-4">
<form-check class="my-3">
<input class="form-check-input" type="checkbox" id="keep-signedin">
<input class="form-check-input" type="checkbox" id="keep-signedin" name="_remember_me">
<label class="form-check-label ms-1" for="keep-signedin">Rester connecté</label>
</form-check>
{# TODO: Mettre le path vers la route mot de passe oublié #}
Expand Down Expand Up @@ -109,16 +109,6 @@
<input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
</form>
</div>
<!-- Copyright-->
<p class="w-100 fs-sm pt-5 mt-auto mb-5" style="max-width: 526px;">
{% set createdWeb = 2023 %}
{% set now = "now"|date("Y") %}
<span class="text-muted">{{ createdWeb == now ? now : (createdWeb ~'-'~ now) }}</span>
<span class="text-muted">&middot;Tous droits réservés. Conçu par</span>
<a class="nav-link d-inline-block p-0 ms-1" href="https://github.com/Papoel" target="_blank" rel="noopener">
Papoel
</a>
</p>
</div>
<!-- Cover image-->
<div class="w-50 bg-size-cover bg-repeat-0 bg-position-center" style="background-image: url({{ asset('assets/img/site/compte/cover.jpg') }});"></div>
Expand Down
Loading