Skip to main content

Django User Sessions NG - a Django package to manage multiple user sessions.

Project description

django-user-sessions-ng

django-user-sessions-ng is a Django package which allows users to have multiple sessions and provides session management through the Django admin interface.

This project is originally inspired by (and based on) the following projects:

  1. django-user-sessions
  2. django-qsessions

The changes made in this repo, however, are very minimal, and the package itself is more like an adaptation for personal use.

Features

  1. Multiple sessions per user.
  2. Session management through the Django admin interface.
  3. Cached session data for faster access.
  4. Device information for each session.
  5. IP address for each session.
  6. (Optional) Location information for each session.

Installation

  1. Install the package using your favorite package manager, for example pip:

    pip install django-user-sessions-ng
    
  2. Add django_user_sessions_ng to your INSTALLED_APPS setting like this::

    INSTALLED_APPS = [
        ...,
        "django_user_sessions_ng",
    ]
    
  3. Add django_user_sessions_ng.middleware.SessionMiddleware to your MIDDLEWARE setting like this:

    MIDDLEWARE = [
        ...,
        "django_user_sessions_ng.middleware.SessionMiddleware",
    ]
    
  4. Set SESSION_ENGINE to django_user_sessions_ng.backends.db or django_user_sessions_ng.backends.cached_db depending on your preferences and whether you need cached db in your Django settings file:

    SESSION_ENGINE = "django_user_sessions_ng.backends.db"
    

    or

    SESSION_ENGINE = "django_user_sessions_ng.backends.cached_db"
    
  5. Run python manage.py migrate to create the necessary models.

  6. (Optional) In order to enable the location information for each session, you will need to install the package called geoip2 and download the GeoLite2 database from MaxMind or using the built-in python manage.py download_geoip_db -k MAXMIND_LICENSE_KEY command (you can get the MAXMIND_LICENSE_KEY by registering at their website and registering a new license key) and set the GEOIP_PATH setting in your Django settings file to the path of the database file or directory containing multiple databases.

    For example:

    GEOIP_PATH = "/path/to/GeoLite2"
    

    or

    GEOIP_PATH = "/path/to/GeoLite2/GeoLite2-City.mmdb"
    

Notes

  1. Since this package replaces the functionality of the default Django session application (django.contrib.sessions), it is recommended to remove the django.contrib.sessions from the INSTALLED_APPS setting as well as django.contrib.sessions.middleware.SessionMiddleware from the MIDDLEWARE setting.

  2. The package provides a management command clearsessions (simply imports the one from the original django.contrib.sessions package) which can be used to clear expired sessions. This command can be run using the following command:

    python manage.py django_user_sessions_ng clearsessions
    
  3. If for some reason the MaxMind base url for download changes, and the package doesn't get updated in time, there's an optional argument -u or --maxmind-geoip-download-base-url for the download_geoip_db command which can be used to specify the base url for downloading the database files.

    For example:

    python manage.py download_geoip_db -k MAXMIND_LICENSE_KEY -u "https://download.maxmind.com/app/geoip_download"
    

Credits

  1. Thanks to JazzBand for their original django-user-sessions implementation.
  2. Thanks to QueraTeam for their original django-qsessions, particularly for their tests and cached_db implementation.

License

MIT

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_ng-0.1.7.tar.gz (38.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_user_sessions_ng-0.1.7-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file django_user_sessions_ng-0.1.7.tar.gz.

File metadata

File hashes

Hashes for django_user_sessions_ng-0.1.7.tar.gz
Algorithm Hash digest
SHA256 13c73a2198c24f87211200579285047b82f474c6ae793c2d205bfc89a4098391
MD5 3b4697261c947f11225f38189951bfcf
BLAKE2b-256 c7b1a3d9b5db196bdc9d0b2ae8965f76b02568782436e12e4e1648c9f2ac9a22

See more details on using hashes here.

File details

Details for the file django_user_sessions_ng-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_user_sessions_ng-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3a9968ac5f2ca132351fb2e3566963a61b90a89a25f7a8bf3a73fdeadb2e51fb
MD5 3c8d330068ee4a722af04931a939201d
BLAKE2b-256 eed23e33416dfecaa3a74706c4dc2cc6f22b252c9fcded2b7ae0353d5e9195cd

See more details on using hashes here.

Supported by

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