Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login hook on Google Appengine

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.

like image 270
Amarnath Ravikumar Avatar asked Jan 11 '11 11:01

Amarnath Ravikumar


1 Answers

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)
like image 55
Kyle Wild Avatar answered Nov 15 '22 09:11

Kyle Wild