[Python-modules-commits] [django-session-security] 03/07: Allow for custom expiration based on request (#65)

Jean-Michel Vourgère nirgal at moszumanska.debian.org
Mon Apr 18 06:12:14 UTC 2016


This is an automated email from the git hooks/post-receive script.

nirgal pushed a commit to branch debian/sid
in repository django-session-security.

commit d0dacbbfcca08ffd4a0429172c9fba986942f5e4
Author: Michael J. Schultz <mjschultz at gmail.com>
Date:   Tue Apr 12 17:26:08 2016 -0500

    Allow for custom expiration based on request (#65)
---
 session_security/middleware.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/session_security/middleware.py b/session_security/middleware.py
index 837fbbd..9cfe949 100644
--- a/session_security/middleware.py
+++ b/session_security/middleware.py
@@ -9,10 +9,8 @@ To install this middleware, add to your ``settings.MIDDLEWARE_CLASSES``::
 Make sure that it is placed **after** authentication middlewares.
 """
 
-import time
 from datetime import datetime, timedelta
 
-from django import http
 from django.contrib.auth import logout
 from django.core.urlresolvers import reverse
 
@@ -29,6 +27,10 @@ class SessionSecurityMiddleware(object):
     def is_passive_request(self, request):
         return request.path in PASSIVE_URLS
 
+    def get_expire_seconds(self, request):
+        """Return time (in seconds) before the user should be logged out."""
+        return EXPIRE_AFTER
+
     def process_request(self, request):
         """ Update last activity time or logout. """
         if not request.user.is_authenticated():
@@ -38,7 +40,8 @@ class SessionSecurityMiddleware(object):
         self.update_last_activity(request, now)
 
         delta = now - get_last_activity(request.session)
-        if delta >= timedelta(seconds=EXPIRE_AFTER):
+        expire_seconds = self.get_expire_seconds(request)
+        if delta >= timedelta(seconds=expire_seconds):
             logout(request)
         elif not self.is_passive_request(request):
             set_last_activity(request.session, now)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/django-session-security.git



More information about the Python-modules-commits mailing list