web/views/sessions.py
changeset 7845 2172978be237
parent 7817 cb6174065c39
child 7854 d95a76df33a9
equal deleted inserted replaced
7841:287813c487b7 7845:2172978be237
    19 object :/
    19 object :/
    20 """
    20 """
    21 
    21 
    22 __docformat__ = "restructuredtext en"
    22 __docformat__ = "restructuredtext en"
    23 
    23 
    24 from cubicweb import RepositoryError, Unauthorized, AuthenticationError
    24 from cubicweb import (RepositoryError, Unauthorized, AuthenticationError,
       
    25                       BadConnectionId)
    25 from cubicweb.web import InvalidSession, Redirect
    26 from cubicweb.web import InvalidSession, Redirect
    26 from cubicweb.web.application import AbstractSessionManager
    27 from cubicweb.web.application import AbstractSessionManager
    27 from cubicweb.dbapi import DBAPISession
    28 from cubicweb.dbapi import DBAPISession
    28 
    29 
    29 
    30 
   117             req.execute('SET X last_login_time NOW WHERE X eid %(x)s',
   118             req.execute('SET X last_login_time NOW WHERE X eid %(x)s',
   118                         {'x' : req.user.eid})
   119                         {'x' : req.user.eid})
   119             req.cnx.commit()
   120             req.cnx.commit()
   120         except (RepositoryError, Unauthorized):
   121         except (RepositoryError, Unauthorized):
   121             req.cnx.rollback()
   122             req.cnx.rollback()
   122         except:
   123         except Exception:
   123             req.cnx.rollback()
   124             req.cnx.rollback()
   124             raise
   125             raise
   125 
   126 
   126     def close_session(self, session):
   127     def close_session(self, session):
   127         """close session on logout or on invalid session detected (expired out,
   128         """close session on logout or on invalid session detected (expired out,
   130         self.info('closing http session %s' % session.sessionid)
   131         self.info('closing http session %s' % session.sessionid)
   131         del self._sessions[session.sessionid]
   132         del self._sessions[session.sessionid]
   132         if session.cnx:
   133         if session.cnx:
   133             try:
   134             try:
   134                 session.cnx.close()
   135                 session.cnx.close()
   135             except:
   136             except BadConnectionId: # expired on the repository side
   136                 # already closed, may occur if the repository session expired
       
   137                 # but not the web session
       
   138                 pass
   137                 pass
   139             session.cnx = None
   138             session.cnx = None