|
@ -23,6 +23,7 @@ import psycopg2 |
|
|
import functools |
|
|
import functools |
|
|
|
|
|
|
|
|
from contextlib import closing |
|
|
from contextlib import closing |
|
|
|
|
|
from datetime import datetime, date |
|
|
|
|
|
|
|
|
from werkzeug.contrib.sessions import SessionStore |
|
|
from werkzeug.contrib.sessions import SessionStore |
|
|
|
|
|
|
|
@ -101,10 +102,19 @@ class PostgresSessionStore(SessionStore): |
|
|
def get(self, sid): |
|
|
def get(self, sid): |
|
|
if not self.is_valid_key(sid): |
|
|
if not self.is_valid_key(sid): |
|
|
return self.new() |
|
|
return self.new() |
|
|
self.cursor.execute("UPDATE sessions SET write_date = now() at time zone 'UTC' WHERE sid=%s;", [sid]) |
|
|
|
|
|
self.cursor.execute("SELECT payload FROM sessions WHERE sid=%s;", [sid]) |
|
|
|
|
|
|
|
|
self.cursor.execute(""" |
|
|
|
|
|
SELECT payload, write_date |
|
|
|
|
|
FROM sessions WHERE sid=%s; |
|
|
|
|
|
""", [sid]) |
|
|
try: |
|
|
try: |
|
|
return self.session_class(json.loads(self.cursor.fetchone()[0]), sid, False) |
|
|
|
|
|
|
|
|
payload, write_date = self.cursor.fetchone() |
|
|
|
|
|
if write_date.date() != datetime.today().date(): |
|
|
|
|
|
self.cursor.execute(""" |
|
|
|
|
|
UPDATE sessions |
|
|
|
|
|
SET write_date = now() at time zone 'UTC' |
|
|
|
|
|
WHERE sid=%s; |
|
|
|
|
|
""", [sid]) |
|
|
|
|
|
return self.session_class(json.loads(payload), sid, False) |
|
|
except Exception: |
|
|
except Exception: |
|
|
return self.session_class({}, sid, False) |
|
|
return self.session_class({}, sid, False) |
|
|
|
|
|
|
|
|