Skip to content

Commit

Permalink
Merge pull request #3 from yscumc/master
Browse files Browse the repository at this point in the history
Middleware polishing.
  • Loading branch information
jpic committed Mar 29, 2013
2 parents 9e73568 + 3285bc8 commit 846685c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions session_security/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from django import http
from django.contrib.auth import logout
from django.core.urlresolvers import reverse

from settings import *

Expand Down Expand Up @@ -48,8 +49,17 @@ def update_last_activity(self, request, now):
last_activity = request.session['_session_security']
server_idle_for = (now - last_activity).seconds

if 'idleFor' in request.GET:
client_idle_for = int(request.GET['idleFor'])
if (request.path == reverse('session_security_ping') and
'idleFor' in request.GET):
# Gracefully ignore non-integer values
try:
client_idle_for = int(request.GET['idleFor'])
except ValueError:
return

# Disallow negative values, causes problems with delta calculation
if client_idle_for < 0:
client_idle_for = 0

if client_idle_for < server_idle_for:
# Client has more recent activity than we have in the session
Expand Down

0 comments on commit 846685c

Please sign in to comment.