Пример #1
0
 def save(self):
     """
     Save the session to the database.
     """
     if not self._invalid:
         session_dict = {"_data" : self.copy(),
                 "_created" : self._created,
                 "_accessed": self._accessed,
                 "_timeout" : self._timeout,
                 "_http_ip" : self._http_ip,
                 "_https_ip" : self._https_ip,
                 "_remember_me" : self._remember_me
         }
         session_key = self._sid
         session_object = cPickle.dumps(session_dict, -1)
         session_expiry = time.time() + self._timeout + \
             CFG_WEBSESSION_ONE_DAY
         uid = self.get('uid', -1)
         run_sql("""
             INSERT session(
                 session_key,
                 session_expiry,
                 session_object,
                 uid
             ) VALUE(%s,
                 %s,
                 %s,
                 %s
             ) ON DUPLICATE KEY UPDATE
                 session_expiry=%s,
                 session_object=%s,
                 uid=%s
         """, (session_key, session_expiry, session_object, uid,
             session_expiry, session_object, uid))
         add_cookies(self._req, self.make_cookies())
Пример #2
0
    def set_remember_me(self, remember_me=True):
        """
        Set/Unset the L{_remember_me} flag.

        @param remember_me: True if the session cookie should last one day or
            until the browser is closed.
        @type remember_me: bool
        """
        self._remember_me = remember_me
        self['_permanent'] = remember_me
        add_cookies(self._req, self.make_cookies())
Пример #3
0
 def invalidate(self):
     """
     Declare the session as invalid.
     """
     cookies = self.make_cookies()
     for cookie in cookies:
         cookie.expires = 0
     add_cookies(self._req, cookies)
     self.delete()
     self._invalid = 1
     if hasattr(self._req, '_session'):
         delattr(self._req, '_session')
Пример #4
0
 def invalidate(self):
     """
     Declare the session as invalid.
     """
     cookies = self.make_cookies()
     for cookie in cookies:
         cookie.expires = 0
     add_cookies(self._req, cookies)
     self.delete()
     self._invalid = 1
     if hasattr(self._req, '_session'):
         delattr(self._req, '_session')
Пример #5
0
    def set_remember_me(self, remember_me=True):
        """
        Set/Unset the L{_remember_me} flag.

        @param remember_me: True if the session cookie should last one day or
            until the browser is closed.
        @type remember_me: bool
        """
        self._remember_me = remember_me
        if remember_me:
            self.set_timeout(CFG_WEBSESSION_EXPIRY_LIMIT_REMEMBER *
                CFG_WEBSESSION_ONE_DAY)
        else:
            self.set_timeout(CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT *
                CFG_WEBSESSION_ONE_DAY)
        add_cookies(self._req, self.make_cookies())
Пример #6
0
    def set_remember_me(self, remember_me=True):
        """
        Set/Unset the L{_remember_me} flag.

        @param remember_me: True if the session cookie should last one day or
            until the browser is closed.
        @type remember_me: bool
        """
        self._remember_me = remember_me
        if remember_me:
            self.set_timeout(CFG_WEBSESSION_EXPIRY_LIMIT_REMEMBER *
                             CFG_WEBSESSION_ONE_DAY)
        else:
            self.set_timeout(CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT *
                             CFG_WEBSESSION_ONE_DAY)
        add_cookies(self._req, self.make_cookies())
Пример #7
0
    def save(self):
        """
        Save the session to the database.
        """
        uid = self.get('uid', -1)
        if not self._invalid and self._sid and self._dirty and (
                uid > 0 or self.is_useful()):
            ## We store something only for real users or useful sessions.
            session_dict = {
                "_data": self.copy(),
                "_created": self._created,
                "_accessed": self._accessed,
                "_timeout": self._timeout,
                "_http_ip": self._http_ip,
                "_https_ip": self._https_ip,
                "_permanent": self._remember_me
            }
            session_key = self._sid
            session_object = cPickle.dumps(session_dict, -1)
            session_expiry = time.time(
            ) + self._timeout + CFG_WEBSESSION_ONE_DAY
            session_expiry = convert_datestruct_to_datetext(
                time.gmtime(session_expiry))

            run_sql(
                """
                INSERT session(
                    session_key,
                    session_expiry,
                    session_object,
                    uid
                ) VALUE(%s,
                    %s,
                    %s,
                    %s
                ) ON DUPLICATE KEY UPDATE
                    session_expiry=%s,
                    session_object=%s,
                    uid=%s
            """, (session_key, session_expiry, session_object, uid,
                  session_expiry, session_object, uid))
            add_cookies(self._req, self.make_cookies())
        ## No more dirty :-)
        self._dirty = False
Пример #8
0
    def save(self):
        """
        Save the session to the database.
        """
        uid = self.get('uid', -1)
        if not self._invalid and self._sid and self._dirty and (uid > 0 or self.is_useful()):
            ## We store something only for real users or useful sessions.
            session_dict = {"_data" : self.copy(),
                    "_created" : self._created,
                    "_accessed": self._accessed,
                    "_timeout" : self._timeout,
                    "_http_ip" : self._http_ip,
                    "_https_ip" : self._https_ip,
                    "_remember_me" : self._remember_me
            }
            session_key = self._sid
            session_object = cPickle.dumps(session_dict, -1)
            session_expiry = time.time() + self._timeout + CFG_WEBSESSION_ONE_DAY
            session_expiry = convert_datestruct_to_datetext(time.gmtime(session_expiry))

            run_sql("""
                INSERT session(
                    session_key,
                    session_expiry,
                    session_object,
                    uid
                ) VALUE(%s,
                    %s,
                    %s,
                    %s
                ) ON DUPLICATE KEY UPDATE
                    session_expiry=%s,
                    session_object=%s,
                    uid=%s
            """, (session_key, session_expiry, session_object, uid,
                session_expiry, session_object, uid))
            add_cookies(self._req, self.make_cookies())
        ## No more dirty :-)
        self._dirty = False
Пример #9
0
 def save(self):
     """
     Save the session to the database.
     """
     if not self._invalid:
         session_dict = {
             "_data": self.copy(),
             "_created": self._created,
             "_accessed": self._accessed,
             "_timeout": self._timeout,
             "_http_ip": self._http_ip,
             "_https_ip": self._https_ip,
             "_remember_me": self._remember_me
         }
         session_key = self._sid
         session_object = cPickle.dumps(session_dict, -1)
         session_expiry = time.time() + self._timeout + \
             CFG_WEBSESSION_ONE_DAY
         uid = self.get('uid', -1)
         run_sql(
             """
             INSERT session(
                 session_key,
                 session_expiry,
                 session_object,
                 uid
             ) VALUE(%s,
                 %s,
                 %s,
                 %s
             ) ON DUPLICATE KEY UPDATE
                 session_expiry=%s,
                 session_object=%s,
                 uid=%s
         """, (session_key, session_expiry, session_object, uid,
               session_expiry, session_object, uid))
         add_cookies(self._req, self.make_cookies())