I want to create custom user checker to validate login action against last accepted eula. ' Idea is quite simple, there will be many versions of eula and user can't login untill he accept the lastest eula.
Scenario is:
- User creates new account and accepts eula.
- Eula gets updated
- User tries to login, but he didnt accept lastest eula
- User gets the same login form but with additional field "accept newest eula"
- User logs in and system inserts information: Current date and time, User id, Eula id to keep track of eula acceptance.
I found this: https://groups.google.com/forum/#!msg/symfony2/D0V0bFks9S0/Qg9mrbpfB3IJ
But unfortunately there is no full version of custom user checker. How do I implement the rest of it?
The answer is actually quite obvious. In your custom bundle:
config.yml
Userchecker:
Why not attach event listener to the
kernel.request
event and watch if the current logged user has accepted the latest EULA?To get the current user you can use something like this:
You can redefine Symfony's user checker service (
security.user_checker
) in your bundle:Then extend Symfony's UserChecker:
The
security.user_checker
service gets called in\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider::authenticate()
during the authentication process