GithubHelp home page GithubHelp logo

rmoorman / django-user-sessions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jazzband/django-user-sessions

0.0 1.0 0.0 226 KB

Extend Django sessions with a foreign key back to the user, allowing enumerating all user's sessions.

Home Page: https://pypi.python.org/pypi/django-user-sessions

License: MIT License

Makefile 1.43% Python 91.68% HTML 6.89%

django-user-sessions's Introduction

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.8, 1.9 and 1.10 on Python 2.7, 3.2, 3.3, 3.4 and 3.5. 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.

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:

python example/manage.py makemigrations user_sessions
git commit -am "Added migrations"

bumpversion [major|minor|patch]
git commit -am "Released [version]"
git tag [version]
python setup.py sdist bdist_wheel upload

License

This project is licensed under the MIT license.

django-user-sessions's People

Contributors

bouke avatar entequak avatar ivorbosloper avatar johnfraney avatar moreati avatar urth avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.