symfony - Event to subscribe if I need to log the user's last activity time? -


i need log last user's activity time, every page load or ajax call counts.

i suppose need subscribe event, have no idea one.

interactiveloginevent mentioned in this answer, understanding fired in event of interactive login only. but, given session last week or more, make record way inaccurate. need event, one?

or, there out of box functionality this?

a solution listener kernelevents::response event, ensuring user authenticated.

namespace appbundle\subscriber;  use symfony\component\eventdispatcher\eventsubscriberinterface; use symfony\component\httpkernel\event\filterresponseevent; use symfony\component\httpkernel\kernelevents; use symfony\component\security\core\authentication\token\storage\tokenstorageinterface;  class lastactivitylistener implements eventsubscriberinterface {     private $tokenstorage;      public function __construct(tokenstorageinterface $tokenstorage)     {         $this->tokenstorage = $tokenstorage;     }      public function onresponse(filterresponseevent $event)     {         $token = $this->tokenstorage->gettoken();          if ($token->isauthenticated()) {             // save last activity $token->getuser(); in place.         }     }      public static function getsubscribedevents()     {         return [             kernelevents::response => 'onresponse',         ];     } } 

also, might need inject storage service save record (e.g. entitymanager if doctrine available).


Comments

Popular posts from this blog

angular - DownloadURL return null in below code -

python 2.7 - Given three nested dictionaries, sort the top two nested dictionaries from a value in the innermost dictionary? -