Skip to main content

Django sessions with a foreign key to the user

Project description

Build Status

Django includes excellent built-in sessions, however all the data is hidden away into a base64 encoded data string. This makes it very difficult to run a query on all active sessions for a particular user. Django User Sessions fixes this and makes session objects just as queryable as other objects.

To get the list of a user’s sessions:

user.session_set.filter(expire_date__gt=now())

Or logout the user everywhere:

user.session_set.all().delete()

The user’s IP address and user agent are also stored on the session. This allows to show a list of active sessions to the user in the admin:

http://i.imgur.com/YV9Nx3f.png

And also in a custom layout:

http://i.imgur.com/d7kZtr9.png

Installation

  1. pip install django-user-sessions

  2. In INSTALLED_APPS replace 'django.contrib.sessions' with 'user_sessions'.

  3. In MIDDLEWARE_CLASSES replace 'django.contrib.sessions.middleware.SessionMiddleware' with 'user_sessions.middleware.SessionMiddleware'.

  4. Add SESSION_ENGINE = 'user_sessions.backends.db'.

  5. Run python manage.py syncdb and start hacking!

GeoIP

You need to setup GeoIP for the location detection to work. See the Django documentation on installing GeoIP.

Example application

Also, have a look at the example application. It includes template examples and shows how to use the session list and delete views.

Compatibility

Tested on Django 1.4, 1.5 and 1.6 with Python 2.7 and 3.3. However it should work fine with Python 2.6 and 3.2 as well.

Contributing

  • Fork the repository on GitHub and start hacking

  • Send a pull request with your changes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-user-sessions-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

File details

Details for the file django-user-sessions-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-user-sessions-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f56594c49d5ad2a871fd9f1952f7319bb288b09f57f053b2d1c59a12a25d9a17
MD5 2b43be7eb68a04fa97c456c8ed9d9d84
BLAKE2b-256 004edb7680fc63903570d1c63165be5d669d954000d7dd05466b8c81357dfa15

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page