|
|
@ -23,6 +23,7 @@ import psycopg2 |
|
|
|
import functools |
|
|
|
|
|
|
|
from contextlib import closing |
|
|
|
from datetime import datetime, date |
|
|
|
|
|
|
|
from werkzeug.contrib.sessions import SessionStore |
|
|
|
|
|
|
@ -101,10 +102,19 @@ class PostgresSessionStore(SessionStore): |
|
|
|
def get(self, sid): |
|
|
|
if not self.is_valid_key(sid): |
|
|
|
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: |
|
|
|
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: |
|
|
|
return self.session_class({}, sid, False) |
|
|
|
|
|
|
|