Every time a user logs in to the application, I want to perform a certain task, say, record the time of login. So I wanted to know if a hook is fired on login by default? If yes, how can I make my module respond to it.
Edit - Assume there are multiple entry points in the application to login.
While there may well be multiple points of entry, it's crucial that your auth/session code conform to the DRY principle.
Once/if you're down to a single code path for logging in, you should be able to find an appropriate place in that code path to do something as simple as this:
user.last_login = time
user.num_logins++
user.save()
Additionally, you could use a memcache cooldown to make sure this only happens once every, say, 30 minutes:
cooldown_memcache_key = "login_cooldown_%s" % user.id
cooldown = memcache.get(cooldown_memcache_key)
if cooldown is None:
user.last_login = time
user.num_logins++
user.save()
memcache.add(cooldown_key, True, 1800)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With