mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
Add anonymous redis session expiration configuration
This commit is contained in:
@@ -10,6 +10,7 @@ from werkzeug.contrib.sessions import SessionStore
|
||||
# this is equal to the duration of the session garbage collector in
|
||||
# openerp.http.session_gc()
|
||||
DEFAULT_SESSION_TIMEOUT = 60 * 60 * 24 * 7 # 7 days in seconds
|
||||
DEFAULT_SESSION_TIMEOUT_ANONYMOUS = 60 * 60 * 3 # 3 hours in seconds
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -18,13 +19,17 @@ class RedisSessionStore(SessionStore):
|
||||
""" SessionStore that saves session to redis """
|
||||
|
||||
def __init__(self, redis, session_class=None,
|
||||
prefix='', expiration=None):
|
||||
prefix='', expiration=None, anon_expiration=None):
|
||||
super(RedisSessionStore, self).__init__(session_class=session_class)
|
||||
self.redis = redis
|
||||
if expiration is None:
|
||||
self.expiration = DEFAULT_SESSION_TIMEOUT
|
||||
else:
|
||||
self.expiration = expiration
|
||||
if anon_expiration is None:
|
||||
self.anon_expiration = DEFAULT_SESSION_TIMEOUT_ANONYMOUS
|
||||
else:
|
||||
self.anon_expiration = anon_expiration
|
||||
self.prefix = u'session:'
|
||||
if prefix:
|
||||
self.prefix = u'%s:%s:' % (
|
||||
@@ -41,7 +46,10 @@ class RedisSessionStore(SessionStore):
|
||||
|
||||
# allow to set a custom expiration for a session
|
||||
# such as a very short one for monitoring requests
|
||||
expiration = session.expiration or self.expiration
|
||||
if session.uid:
|
||||
expiration = session.expiration or self.expiration
|
||||
else:
|
||||
expiration = session.expiration or self.anon_expiration
|
||||
if _logger.isEnabledFor(logging.DEBUG):
|
||||
if session.uid:
|
||||
user_msg = "user '%s' (id: %s)" % (
|
||||
|
||||
Reference in New Issue
Block a user