Skip to content

rhoog/django-user-sessions

 
 

Repository files navigation

Django User Sessions

Build Status Test Coverage PyPI

Django includes excellent built-in sessions, however all the data is hidden away into base64 encoded data. 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 a first class citizen like other ORM objects.

Also, have a look at the online example app, hosted by Heroku. It also contains the package django-two-factor-auth, but that application is not a dependency for this package. Also have a look at the bundled example templates and views to see how you can integrate the application into your project.

Compatible with Django 1.4, 1.5, 1.6 and 1.7 on Python 2.6, 2.7, 3.2, 3.3 and 3.4. Documentation is available at readthedocs.org.

Features

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. Add url(r'', include('user_sessions.urls', 'user_sessions')), to your urls.py.
  6. Run python manage.py syncdb (or migrate) and browse to /account/sessions/.

GeoIP

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

Contribute

  • Fork the repository on GitHub and start hacking.
  • Run the tests.
  • Send a pull request with your changes.
  • Provide a translation using Transifex.

License

This project is licensed under the MIT license.

About

Django sessions with a foreign key to the user

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 92.4%
  • HTML 6.3%
  • Makefile 1.3%