Esempio n. 1
0
 def invalidate(self):
     """
     Declare the session as invalid.
     """
     cookie = self.make_cookie()
     cookie.expires = 0
     add_cookie(self._req, cookie)
     self.delete()
     self._invalid = 1
     if hasattr(self._req, '_session'):
         delattr(self._req, '_session')
Esempio n. 2
0
 def invalidate(self):
     """
     Declare the session as invalid.
     """
     cookie = self.make_cookie()
     cookie.expires = 0
     add_cookie(self._req, cookie)
     self.delete()
     self._invalid = 1
     if hasattr(self._req, '_session'):
         delattr(self._req, '_session')
Esempio n. 3
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_cookie(self._req, self.make_cookie())
Esempio n. 4
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_cookie(self._req, self.make_cookie())
Esempio n. 5
0
    def __init__(self, req, sid=None):
        self._remember_me = False
        self._req, self._sid, self._secret = req, sid, None
        self._lock = CFG_WEBSESSION_ENABLE_LOCKING
        self._new = 1
        self._created = 0
        self._accessed = 0
        self._timeout = 0
        self._locked = 0
        self._invalid = 0
        self._http_ip = None
        self._https_ip = None

        dict.__init__(self)

        if not self._sid:
            # check to see if cookie exists
            cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME)
            if cookie:
                self._sid = cookie.value

        if self._sid:
            if not _check_sid(self._sid):
                if sid:
                    # Supplied explicitly by user of the class,
                    # raise an exception and make the user code
                    # deal with it.
                    raise ValueError("Invalid Session ID: sid=%s" % sid)
                else:
                    # Derived from the cookie sent by browser,
                    # wipe it out so it gets replaced with a
                    # correct value.
                    self._sid = None

        if self._sid:
            # attempt to load ourselves
            self.lock()
            if self.load():
                self._new = 0

        if self._new:
            # make a new session
            if self._sid:
                self.unlock() # unlock old sid
            self._sid = _new_sid(self._req)
            self.lock()                 # lock new sid
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                self._https_ip = remote_ip
            else:
                self._http_ip = remote_ip
            add_cookie(self._req, self.make_cookie())
            self._created = time.time()
            self._timeout = CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT * \
                CFG_WEBSESSION_ONE_DAY

        self._accessed = time.time()

        # need cleanup?
        if random.randint(1, CFG_WEBSESSION_CLEANUP_CHANCE) == 1:
            self.cleanup()
Esempio n. 6
0
    def __init__(self, req, sid=None):
        self._remember_me = False
        self._req, self._sid, self._secret = req, sid, None
        self._lock = CFG_WEBSESSION_ENABLE_LOCKING
        self._new = 1
        self._created = 0
        self._accessed = 0
        self._timeout = 0
        self._locked = 0
        self._invalid = 0
        self._http_ip = None
        self._https_ip = None

        dict.__init__(self)

        if not self._sid:
            # check to see if cookie exists
            cookie = get_cookie(req, CFG_WEBSESSION_COOKIE_NAME)
            if cookie:
                self._sid = cookie.value

        if self._sid:
            if not _check_sid(self._sid):
                if sid:
                    # Supplied explicitly by user of the class,
                    # raise an exception and make the user code
                    # deal with it.
                    raise ValueError("Invalid Session ID: sid=%s" % sid)
                else:
                    # Derived from the cookie sent by browser,
                    # wipe it out so it gets replaced with a
                    # correct value.
                    self._sid = None

        if self._sid:
            # attempt to load ourselves
            self.lock()
            if self.load():
                self._new = 0

        if self._new:
            # make a new session
            if self._sid:
                self.unlock()  # unlock old sid
            self._sid = _new_sid(self._req)
            self.lock()  # lock new sid
            remote_ip = self._req.remote_ip
            if self._req.is_https():
                self._https_ip = remote_ip
            else:
                self._http_ip = remote_ip
            add_cookie(self._req, self.make_cookie())
            self._created = time.time()
            self._timeout = CFG_WEBSESSION_EXPIRY_LIMIT_DEFAULT * \
                CFG_WEBSESSION_ONE_DAY

        self._accessed = time.time()

        # need cleanup?
        if random.randint(1, CFG_WEBSESSION_CLEANUP_CHANCE) == 1:
            self.cleanup()