Is there a way I can store when was the last time a user logged in?
I’m using symfony2, and everything’s working alright with the security configuration.
I’ve seen this Security and login on a Symfony 2 based project, which is a similar question, but it just doesn’t fit my needs.
Is there any other solution?
You can create an
AuthenticationHandlerthat Symfony will call when user login successfully, you can save the login time into aUserentity property (supposing that you have this scenario).First, create the success authentication handler:
Then you need to register the authentication handler as a service in a configuration file, for example,
src/Acme/TestBundle/resources/Config/services.ymlAnd configure the login form to use the created handler, check out your
security.ymlObviously, for this to work, you need to have a
Userentity with aloginTimeproperty and the corresponding setter. And you need to configure the login to use theUserentity repository as user provider and theDaoAuthenticationProvider, as explained here: http://symfony.com/doc/current/book/security.html#loading-users-from-the-database.