I'd like to track some data when users are logging in (success and failure) but I don't really know how to do it.
The firewall looks like this :
$app->register(new Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'secured' => array(
'pattern' => '^/',
'anonymous' => true,
'logout' => true,
'form' => array('login_path' => '/login',
'check_path' => '/login_check',
),
'users' => $app->share(function () use ($app) {
return $app["dao.identifiant"];
}),
),
),
));
I found that I have to register a service like :
$app['security.authentication.success_handler.secured'] = $app->share(function ($app) {
...
});
And I also created a custom class implementing the AuthenticationSuccessHandlerInterface :
<?php
namespace myproject\Authentication;
use Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
class CustomAuthenticationSuccessHandler implements AuthenticationSuccessHandlerInterface
{
public function onAuthenticationSuccess(Request $request, TokenInterface $token)
{
...
}
}
I have a class called Connection in which I have a function to record some information in my database (like the user ID, date & time of the connection, if he failed or succeded to log in, etc.). How can I manage to call this function whenever a user tries to log in ?
Thanks !