Changeset 3444

Show
Ignore:
Timestamp:
09/02/07 12:57:22 (1 year ago)
Author:
faide
Message:

Applying patch from ticket #1406 provided by "j". Makes sure the cookies has the same timeout as the session in order to not loose the session if the user closes the browser.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/turbogears/visit/api.py

    r3367 r3444  
    44from random import random 
    55from datetime import timedelta, datetime 
     6import time 
    67 
    78import cherrypy 
     
    121122        # By default, I don't specify the cookie domain. 
    122123        self.cookie_domain = get("visit.cookie.domain", None) 
     124        self.cookie_max_age = int(get("visit.timeout", "20")) * 60 
    123125        assert self.cookie_domain != "localhost", \ 
    124126               "localhost is not a valid value for visit.cookie.domain. Try None instead." 
     
    193195        cookies[self.cookie_name] = visit_key 
    194196        cookies[self.cookie_name]['path'] = self.cookie_path 
     197        # We'd like to use the "max-age" param as  
     198        #   http://www.faqs.org/rfcs/rfc2109.html indicates but IE doesn't  
     199        #   save it to disk and the session is lost if people close  
     200        #   the browser  
     201        #   So we have to use the old "expires" ... sigh ...  
     202        #cookies[self.cookie_name]['max-age']= self.cookie_max_age  
     203        gmt_expiration_time = time.gmtime(time.time() + self.cookie_max_age)  
     204        cookies[self.cookie_name]['expires'] = time.strftime(  
     205                "%a, %d-%b-%Y %H:%M:%S GMT", gmt_expiration_time) 
     206 
    195207        if self.cookie_secure: 
    196208            cookies[self.cookie_name]['secure'] = True