I am currently working on developing a Symfony2 application that will not only accept user registrations, but allow visitors to go through almost the entire flow of the site without creating an account or logging in. Design ideas look something like this (suggestions / improvements are welcome):
- When a user logs into his account, data will be saved for users / related objects as usual.
- When an anonymous user first enters the site, an “anonymous user object” is created for them, as if they were registered, but with something like
USER_<session_id> as an identifier instead of a personalized username. Any activity that they perform on the site is stored for this anonymous user object. - When an anonymous user decides to register, their anonymous user object is updated to the registered user object, saving their data for future use.
- If an anonymous user leaves the site without registering, the anonymous user object must be cleaned up after a while to prevent the collection of dead data.
What is the best way to do this? In particular, what is considered “best practice” for creating / manipulating a user object for an anonymous user without the need to place code in each controller?
source share