Development

This commit is contained in:
Matthew Grotke 2026-06-12 23:31:55 -04:00
parent 025adb9f15
commit 5b1f905ed0
7 changed files with 38 additions and 47 deletions

View file

@ -4,6 +4,7 @@ import time
import uuid
from flask.sessions import SessionInterface, SessionMixin
from werkzeug.datastructures import CallbackDict
import settings as _settings
_LEVEL_INT_TO_STR = {0: 'nothing', 1: 'viewer', 2: 'administrator', 3: 'manager'}
@ -36,7 +37,7 @@ class SqliteSessionInterface(SessionInterface):
try:
con = self._connect()
row = con.execute(
'''SELECT s.session_id, s.account_id, s.tz_offset_seconds,
'''SELECT s.session_id, s.account_id, s.timezone,
s.preferences_json, s.flashes_json,
a.email, a.access_level
FROM sessions s
@ -47,12 +48,12 @@ class SqliteSessionInterface(SessionInterface):
if row:
prefs = json.loads(row['preferences_json'] or '{}')
flashes = json.loads(row['flashes_json'] or '[]')
tz = str(row['timezone'] or '') or _settings.get_host_timezone()
data = {
'account_id': str(row['account_id']),
'email_address': str(row['email']),
'access_level': _LEVEL_INT_TO_STR.get(row['access_level'], 'viewer'),
'tz_offset_seconds': int(row['tz_offset_seconds']),
'timezone': str(prefs.get('timezone', '')),
'timezone': tz,
'apply_changes_immediately': bool(prefs.get('apply_changes_immediately', False)),
'_flashes': flashes,
'_permanent': True,
@ -93,24 +94,23 @@ class SqliteSessionInterface(SessionInterface):
try:
con = self._connect()
if account_id:
prefs = json.dumps({
'timezone': session.get('timezone', ''),
prefs = json.dumps({
'apply_changes_immediately': bool(session.get('apply_changes_immediately', False)),
})
tz_offset = int(session.get('tz_offset_seconds', 0))
tz = session.get('timezone', '')
con.execute('INSERT OR IGNORE INTO clients (cookie_unique_token) VALUES (?)', (session.sid,))
con.execute(
'''INSERT INTO sessions
(session_id, account_id, tz_offset_seconds, preferences_json,
(session_id, account_id, timezone, preferences_json,
flashes_json, session_started_ts, last_seen_ts)
VALUES (?,?,?,?,?,?,?)
ON CONFLICT(session_id) DO UPDATE SET
account_id=excluded.account_id,
tz_offset_seconds=excluded.tz_offset_seconds,
timezone=excluded.timezone,
preferences_json=excluded.preferences_json,
flashes_json=excluded.flashes_json,
last_seen_ts=excluded.last_seen_ts''',
(session.sid, account_id, tz_offset, prefs, flashes_json, now, now)
(session.sid, account_id, tz, prefs, flashes_json, now, now)
)
else:
con.execute(