Skip to main content

Django sessions with a foreign key to the user

Project description

====================
Django User Sessions
====================

.. image:: https://travis-ci.org/Bouke/django-user-sessions.png?branch=master
:alt: Build Status
:target: https://travis-ci.org/Bouke/django-user-sessions

.. image:: https://coveralls.io/repos/Bouke/django-user-sessions/badge.png?branch=master
:alt: Test Coverage
:target: https://coveralls.io/r/Bouke/django-user-sessions?branch=master

.. image:: https://badge.fury.io/py/django-user-sessions.png
:alt: PyPI
:target: https://pypi-hypernode.com/pypi/django-user-sessions

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 and 1.6 on Python 2.6, 2.7, 3.2 and 3.3.
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:

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

And also in a custom layout:

.. image:: 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`_.

.. _installing GeoIP:
https://docs.djangoproject.com/en/1.6/ref/contrib/gis/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.


.. _Transifex: https://www.transifex.com/projects/p/django-user-sessions/
.. _`readthedocs.org`: http://django-user-sessions.readthedocs.org/
.. _`example app`: http://example-two-factor-auth.herokuapp.com
.. _Heroku: https://www.heroku.com

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.3.tar.gz (14.7 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-user-sessions-0.1.3.tar.gz
Algorithm Hash digest
SHA256 dceb11b5456b06920705f222732817e6f4504ad6c3635531087273fc734a116b
MD5 24fae391fdeda2e2de2f54e2e111c67f
BLAKE2b-256 447015f4fef3bcce2a2c3cca7a8aeab23decfcc78849698803be1a621b60815f

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