In the first part of your question, I had something similar (for example, save the last date and time the user logged in). I went along the service route, which was fired for the event. In the services configuration (XML example here):
<services>
<service id="my.login.listener" class="My\OwnBundle\Event\LoginEventListener">
<tag name="kernel.event_listener" event="security.interactive_login" />
</service>
</services>
and then create the above class in the appropriate place in your kit:
namespace My\OwnBundle\Event;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use My\OwnBundle\User\User as MyUser;
class LoginEventListener
{
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
$token = $event->getAuthenticationToken();
if ($token && $token->getUser() instanceof MyUser)
{
}
}
}
I would suggest that you can extend this to the second part of your question, but I did not :-)
source
share