feat: add 'remember me' functionality

This commit is contained in:
Björn Fromme
2024-10-30 10:23:49 +01:00
parent 69553fb1b3
commit 5221b02af6
4 changed files with 49 additions and 1 deletions
+5
View File
@@ -26,6 +26,11 @@ security:
logout:
path: app_security_logout
target: app_security_login
remember_me:
secret: '%kernel.secret%'
lifetime: 604800
token_provider:
doctrine: true
access_control:
- { path: '^/', roles: PUBLIC_ACCESS, requires_channel: https }
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20241030091854 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE rememberme_token (series VARCHAR(88) NOT NULL, value VARCHAR(88) NOT NULL, lastUsed DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', class VARCHAR(100) NOT NULL, username VARCHAR(200) NOT NULL, PRIMARY KEY(series)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE rememberme_token');
}
}
+5 -1
View File
@@ -17,6 +17,7 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
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\Passport;
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport;
@@ -73,7 +74,10 @@ class BpnAuthenticator extends AbstractLoginFormAuthenticator implements Authent
return $user;
}),
[new CsrfTokenBadge('authenticate', $csrfToken)]
[
new CsrfTokenBadge('authenticate', $csrfToken),
new RememberMeBadge(),
]
);
}
+8
View File
@@ -40,6 +40,14 @@
required
autocomplete="current-password">
</div>
<div class="flex items-start mb-6">
<label for="rememberme" class="flex h-6 items-center">
<input type="checkbox" id="rememberme" name="_remember_me" class="h-4 w-4 rounded text-primary">
<span class="block ml-3 leading-6">
angemeldet bleiben
</span>
</label>
</div>
<button type="submit" class="btn w-full">
Login
</button>