I followed the CookBook tutorial. How can I decide the duration of the cookie? I’m not even sure it’s there because I don’t see it in the dev tool.
It’s my login form so I think the form protection is useful right? I don’t have an extension except ADBlock so I don’t see what could be blocking?
My code if it can help ?
APPLICATION.PHP
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
{
$service = new AuthenticationService();
// Define where users should be redirected to when they are not authenticated
$service->setConfig([
'unauthenticatedRedirect' => Router::url([
'prefix' => false,
'plugin' => null,
'controller' => 'Archives',
'action' => 'index',
]),
'queryParam' => 'redirect',
]);
$fields = [
IdentifierInterface::CREDENTIAL_USERNAME => 'email',
IdentifierInterface::CREDENTIAL_PASSWORD => 'password'
];
// Load the authenticators. Session should be first.
$service->loadAuthenticator('Authentication.Session');
$service->loadAuthenticator('Authentication.Form', [
'fields' => $fields,
'loginUrl' => Router::url([
'prefix' => false,
'plugin' => null,
'controller' => 'Users',
'action' => 'login',
]),
]);
$service->loadAuthenticator('Authentication.Cookie', [
'fields' => $fields,
'loginUrl' => '/users/login',
]);
// Load identifiers
$service->loadIdentifier('Authentication.Password', compact('fields'));
return $service;
}
USERS CONTROLLER
public function login()
{
$this->viewBuilder()->setLayout('login');
$result = $this->Authentication->getResult();
if ($result->isValid()) {
$this->Flash->success(__("Succès : Vous êtes connecté."));
$this->redirect(['controller' => 'Archives', 'action' => 'index']);
}
if ($this->request->is('post') && !$result->isValid()) {
$this->Flash->error('Erreur : Identifiants incorrects.');
}
}
LOGIN VIEW
<div class="mt-3">
<?php echo $this->Form->create();?>
<div class="form-floating">
<?php
echo $this->Form->control('email',[
'class'=>'form-control',
'id'=>'floatingInput',
'placeholder'=>"Adresse email",
'label'=>false,
]);
?>
</div>
<div class="form-floating">
<?php
echo $this->Form->control('password',[
'class'=>'form-control',
'placeholder'=>"Mot de passe",
'label'=>false,
]);
?>
</div>
<div class="checkbox mb-3">
<?= $this->Form->control('remember_me', ['type' => 'checkbox']); ?>
</div>
<?php
echo $this->Form->button("Connexion",[
'class'=>'w-100 btn btn-lg btn-primary',
]);
echo $this->Form->end();
?>
</div>