Skip to main content

Django sessions with a foreign key to the user

Project description

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. It is a drop-in replacement for django.contrib.sessions.

I would love to hear your feedback on this package. If you run into problems, please file an issue on GitHub, or contribute to the project by forking the repository and sending some pull requests. The package is translated into English, Dutch and other languages. Please contribute your own language using Transifex.

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 2.2 and 3.0 on Python 3.5, 3.6, 3.7 and 3.8. 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

Refer to the installation instructions in the documentation.

GeoIP

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

Getting help

For general questions regarding this package, please hop over to Stack Overflow. If you think there is an issue with this package; check if the issue is already listed (either open or closed), and file an issue if it’s not.

Development

How to contribute

  • Fork the repository on GitHub and start hacking.

  • Run the tests.

  • Send a pull request with your changes.

  • Provide a translation using Transifex.

Running tests

This project aims for full code-coverage, this means that your code should be well-tested. Also test branches for hardened code. You can run the full test suite with:

make test

Or run a specific test with:

make test TARGET=tests.tests.MiddlewareTest

For Python compatibility, tox is used. You can run the full test suite with:

tox

Releasing

The following actions are required to push a new version:

  • Update release notes

  • If any new translations strings were added, push the new source language to Transifex. Make sure translators have sufficient time to translate those new strings:

    make tx-push
  • Add migrations:

    python example/manage.py makemigrations user_sessions
    git commit user_sessions/migrations -m "Added migrations"
  • Update translations:

    make tx-pull
  • Package and upload:

    bumpversion [major|minor|patch]
    git push && git push --tags
    python setup.py sdist bdist_wheel
    twine upload dist/*

License

This project is licensed under the MIT license.

Credits

This library was written by Bouke Haarsma.

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

Uploaded Source

Built Distribution

django_user_sessions-1.7.1-py2.py3-none-any.whl (38.7 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: django-user-sessions-1.7.1.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2

File hashes

Hashes for django-user-sessions-1.7.1.tar.gz
Algorithm Hash digest
SHA256 1e8c9c06f932e0d3090defdd2977221fe2465ed838655856532da1325a9a5180
MD5 dc8898a308e4810fe699223c1daf60cc
BLAKE2b-256 449aa91d5b06bc2aeeb7e89dbbde18898667343fc5dce15d327dfbbb3354eb8d

See more details on using hashes here.

File details

Details for the file django_user_sessions-1.7.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_user_sessions-1.7.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 38.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2

File hashes

Hashes for django_user_sessions-1.7.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e23d8860eb5a913ee345c198401b179af092b39d33eac61f1e49c9091e74e38c
MD5 a4dc98fc3944efa61c5ca58a0506d9d5
BLAKE2b-256 59d51c56a02b4eb874100cfd43457663fd5f259b0741cccdd306057ffabe7b92

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