MCPcopy Index your code
hub / github.com/pgadmin-org/pgadmin4 / ManagedSessionInterface

Class ManagedSessionInterface

web/pgadmin/utils/session.py:437–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435
436
437class ManagedSessionInterface(SessionInterface):
438 def __init__(self, manager):
439 self.manager = manager
440 signer.Signer.default_digest_method = \
441 eval(config.SESSION_DIGEST_METHOD)
442
443 def open_session(self, app, request):
444 cookie_val = request.cookies.get(app.config['SESSION_COOKIE_NAME'])
445
446 if not cookie_val or '!' not in cookie_val:
447 return self.manager.new_session()
448
449 sid, digest = cookie_val.split('!', 1)
450
451 if self.manager.exists(sid):
452 return self.manager.get(sid, digest)
453
454 return self.manager.new_session()
455
456 def save_session(self, app, session, response):
457 domain = self.get_cookie_domain(app)
458 if not session:
459 self.manager.remove(session.sid)
460 if session.modified:
461 response.delete_cookie(app.config['SESSION_COOKIE_NAME'],
462 domain=domain)
463 return
464
465 if not session.modified:
466 # No need to save an unaltered session
467 # TODO: put logic here to test if the cookie is older than N days,
468 # if so, update the expiration date
469 return
470
471 self.manager.put(session)
472 session.modified = False
473
474 cookie_exp = self.get_expiration_time(app, session)
475 response.set_cookie(
476 app.config['SESSION_COOKIE_NAME'],
477 '%s!%s' % (session.sid, session.hmac_digest),
478 expires=cookie_exp,
479 path=config.SESSION_COOKIE_PATH,
480 secure=config.SESSION_COOKIE_SECURE,
481 httponly=config.SESSION_COOKIE_HTTPONLY,
482 samesite=config.SESSION_COOKIE_SAMESITE,
483 domain=domain
484 )
485
486
487def create_session_interface(app, skip_paths=[]):

Callers 1

create_session_interfaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected