/usr/lib/python2.7/dist-packages/trytond/ir/session.py is in tryton-server 3.8.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
try:
import simplejson as json
except ImportError:
import json
import uuid
import datetime
from trytond.model import ModelSQL, fields
from trytond.config import config
from .. import backend
from ..transaction import Transaction
__all__ = [
'Session', 'SessionWizard',
]
class Session(ModelSQL):
"Session"
__name__ = 'ir.session'
_rec_name = 'key'
key = fields.Char('Key', required=True, select=True)
@classmethod
def __setup__(cls):
super(Session, cls).__setup__()
cls.__rpc__ = {}
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(Session, cls).__register__(module_name)
table = TableHandler(Transaction().cursor, cls, module_name)
table.index_action('create_uid', 'add')
@staticmethod
def default_key():
return uuid.uuid4().hex
@classmethod
def check(cls, user, key):
"Check user key and delete old one"
now = datetime.datetime.now()
timeout = datetime.timedelta(
seconds=config.getint('session', 'timeout'))
sessions = cls.search([
('create_uid', '=', user),
])
find = False
for session in sessions:
timestamp = session.write_date or session.create_date
if abs(timestamp - now) < timeout:
if session.key == key:
find = True
else:
cls.delete([session])
return find
@classmethod
def reset(cls, session):
"Reset session timestamp"
sessions = cls.search([
('key', '=', session),
])
cls.write(sessions, {})
class SessionWizard(ModelSQL):
"Session Wizard"
__name__ = 'ir.session.wizard'
data = fields.Text('Data')
@classmethod
def __setup__(cls):
super(SessionWizard, cls).__setup__()
cls.__rpc__ = {}
@staticmethod
def default_data():
return json.dumps({})
|