From 5e6b054896e913e7000f3ed759e7e138e4f6c60c Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 30 Jun 2015 20:02:09 +0200 Subject: [PATCH] extend cookie age if its still used --- pandora/settings.py | 4 ++++ pandora/user/middleware.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 pandora/user/middleware.py diff --git a/pandora/settings.py b/pandora/settings.py index 9112ebcb..efa2da1b 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -87,6 +87,7 @@ MIDDLEWARE_CLASSES = ( 'django.contrib.messages.middleware.MessageMiddleware', 'ox.django.middleware.ExceptionMiddleware', 'ox.django.middleware.ChromeFrameMiddleware', + 'user.middleware.UpdateSession', ) ROOT_URLCONF = 'urls' @@ -205,6 +206,9 @@ MEDIA_PREFIX='' SESSION_COOKIE_AGE=60*24*60*60 +# Extend cookie age if session is older +SESSION_UPDATE=24*60*60 + SCRIPT_ROOT = normpath(join(PROJECT_ROOT, '..', 'scripts')) #change script to customize ITEM_POSTER = join(SCRIPT_ROOT, 'poster.py') diff --git a/pandora/user/middleware.py b/pandora/user/middleware.py new file mode 100644 index 00000000..fc4da9b3 --- /dev/null +++ b/pandora/user/middleware.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 +from django.conf import settings +from django.contrib.sessions.models import Session + +class UpdateSession(object): + def process_request(self, request): + if request.user.is_authenticated(): + expire_date = Session.objects.get(session_key=request.session.session_key).expire_date + if (request.session.get_expiry_date() - expire_date).total_seconds() > settings.SESSION_UPDATE: + request.session.modified = True + + def process_response(self, request, response): + return response