django-auth-remember 0.3

Django app for remember-me functionality (using a token)

Add the auth_remember authentication backend to django:

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'auth_remember.backend.AuthRememberBackend',
)

Add the remember middleware in your settings, right after AuthenticationMiddleware:

MIDDLEWARE_CLASSES = (
    ...
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'auth_remember.middleware.AuthRememberMiddleware',
    ...
)

Add auth_remember to INSTALLED_APPS:

INSTALLED_APPS = (
    'auth_remember',
)

Set the cookie name and expire time (optional):

AUTH_REMEMBER_COOKIE_NAME = 'remember_token'
AUTH_REMEMBER_COOKIE_AGE = 86400 * 28  # 4 weeks by default

Set the expire time of the session to browser close (optional):

SESSION_EXPIRE_AT_BROWSER_CLOSE = True

To remember a user add the following code to your authentication handler:

from auth_remember import remember_user
remember_user(request, user)

Use the user.is_fresh attribute to test if the user is fresh:

{% if user.is_fresh %}
    This user session is fresh
{% else %}
    This user session is NOT fresh
{% endif %}

Under the hood auth_remember uses the session var AUTH_REMEMBER_FRESH to indicate if the user session is fresh. The name of the session var can be changed by setting the AUTH_REMEMBER_SESSION_KEY in you're settings file.

TODOs

  • Introduce settings for AUTH_REMEMBER_COOKIE_DOMAIN
MIT

Author

Michael van Tellingen

Pip

django-auth-remember==0.3

Classifiers

  • Environment :: Web Environment
  • Framework :: Django
  • Intended Audience :: Developers
  • License :: OSI Approved :: MIT License
  • Operating System :: OS Independent
  • Programming Language :: Python
  • Development Status :: 4 - Beta
  • Topic :: Software Development
File Type Python Version Uploaded On Downloads
django-auth-remember-0.3.tar.gz Source Feb. 28, 2012 3,428
Version Release Date
0.3 Feb. 28, 2012
0.2 Nov. 29, 2011
0.1 Nov. 28, 2011
Date Package Version Action
Aug. 24, 2015, 10:58 p.m. django-auth-remember 0.2 Release Created
Aug. 24, 2015, 10:58 p.m. django-auth-remember 0.3 Release Created
Aug. 24, 2015, 10:58 p.m. django-auth-remember 0.1 Release Created
Aug. 24, 2015, 10:58 p.m. django-auth-remember Package Created