コード例 #1
0
 def change_sid(self, new_sid):
     assert not self.req.is_authenticated, \
            'Cannot change ID of authenticated session'
     assert new_sid, 'Session ID cannot be empty'
     if new_sid == self.sid:
         return
     if not self._valid_sid_re.match(new_sid):
         raise TracValueError(_("Session ID must be alphanumeric."),
                              _("Error renaming session"))
     with self.env.db_transaction as db:
         if db("SELECT sid FROM session WHERE sid=%s", (new_sid, )):
             raise TracError(
                 _(
                     "Session '%(id)s' already exists. "
                     "Please choose a different session ID.",
                     id=new_sid), _("Error renaming session"))
         self.env.log.debug("Changing session ID %s to %s", self.sid,
                            new_sid)
         db("UPDATE session SET sid=%s WHERE sid=%s AND authenticated=0",
            (new_sid, self.sid))
         db(
             """UPDATE session_attribute SET sid=%s
               WHERE sid=%s and authenticated=0
               """, (new_sid, self.sid))
     self.sid = new_sid
     self.bake_cookie()
コード例 #2
0
    def get_session(self, sid, authenticated=False):
        refresh_cookie = False

        if not authenticated and not self._valid_sid_re.match(sid):
            raise TracValueError(_("Session ID must be alphanumeric."))
        if self.sid and sid != self.sid:
            refresh_cookie = True

        super(Session, self).get_session(sid, authenticated)
        if self.last_visit and time_now() - self.last_visit > UPDATE_INTERVAL:
            refresh_cookie = True

        # Refresh the session cookie if this is the first visit after a day
        if not authenticated and refresh_cookie:
            self.bake_cookie()