I am building a web application with Symfony 2, using the FOSUserBundle bundle.
Users create an account, login and start using the application.
What I want to
You can also do this solution if you want to just check once:
There is an event triggered each time there's a successful login being done. The event is named:
security.interactive_login
In order to subscribe to this event, you have to create a service container with your created class let's say "LoginListener.php" and inject the tag "kernel.even_listener" with the event "security.interactive_login":
in LoginListener:
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
public function onLoginSuccess(InteractiveLoginEvent $event) {
if ($this->_security->isGranted('IS_AUTHENTICATED_FULLY')) {
//your code here...
}
}
you can also add other dependencies and inject it to the constructor, in my case I had to inject security, session and container:
public function __construct(SecurityContext $security, Session $session, ContainerInterface $container) {
}