0

Is there a way to see if a user is currently logged in and active on a site?

For example, I know you can check the authentication token of the user and see if he is still 'actively logged in', but this doesn't tell me much, since the user could technically be logged in for two weeks, though only actively on the site for one minute of that duration. last_login would be equally unhelpful.

What would be a good method in django to check to see if the user is currently active? I have done this in Google Analytics, but was wondering how I could do an entirely-django approach.

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    Define active on the site. – reptilicus Apr 22 '13 at 04:05
  • 1
    You could probably use something like a "[last seen](https://bitbucket.org/ferranp/django-last-seen)" middleware for this and filter with some threshold (the link I posted uses a 2 hours interval, so this will probably need some tweaking too). Edit: The SO question give by @BurhanKhalid accomplishes the same thing in a really elegant way. – nvlass Apr 22 '13 at 04:06

1 Answers1

0

There are several ways to determine user activity:

1) Use javascript to send periodic requests to server.

+: You will be able to determine user activity despite he actively working on site or just keep open window.

-: Too many requests.

2) Use django middleware

-: Can`t determine user activity if he keeps only open window

3) Use asynchronous framework to keep long-lived connection. For example tornado.

It is cleanest way but the most labor-intensive.

Sergei
  • 280
  • 1
  • 10