Skip to main content

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

Project description

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.

More information

See:

TODOs

  • Introduce settings for AUTH_REMEMBER_COOKIE_DOMAIN

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-auth-remember-0.3.tar.gz (7.7 kB view details)

Uploaded Source

File details

Details for the file django-auth-remember-0.3.tar.gz.

File metadata

File hashes

Hashes for django-auth-remember-0.3.tar.gz
Algorithm Hash digest
SHA256 cdf2fddc0cc632344232e225b5379d6485cfe1b09aa9116d24b3843fd71c4bfe
MD5 8e3d42f8e48fd765e210b8fc01648651
BLAKE2b-256 8cb62d3221324372058901643ab03e9eeeea42e35c6ebb58f105634ba4b89997

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