Ticket #6353: trac_6353-cookies-diff-ports.patch

File trac_6353-cookies-diff-ports.patch, 3.1 KB (added by timdumol, 10 years ago)

Appends port number to the cookie names.

  • sagenb/notebook/guard.py

    # HG changeset patch
    # User Tim Dumol <tim@timdumol.com>
    # Date 1263899175 -28800
    # Node ID 79a1e5c34aa8cda96c1998b56bbdeafa3cb678b4
    # Parent  8c1cb361586381d0fb223baf1b58abc22d9cccc3
    #6353 change cookies structure to support multiple notebook logins at different ports
    
    diff -r 8c1cb3615863 -r 79a1e5c34aa8 sagenb/notebook/guard.py
    a b  
    2222from twisted.web2 import iweb
    2323from twisted.web2 import server
    2424
     25
    2526#standard library
    2627import random
    2728import time
     
    260261            return avatars.TokenCred(request.args.get('startup_token', [''])[0])
    261262        if request.headers.getHeader('cookie'):
    262263            for C in request.headers.getHeader('cookie'):
    263                 if C.name == 'cookie_test':
     264                if C.name == 'cookie_test_%s' % twist.notebook.port:
    264265                    username = request.args.get('email', [''])[0]
    265266                    password = request.args.get('password', [''])[0]
    266267                else:
     
    303304    if cookies is None:
    304305        return None
    305306    for C in cookies:
    306         if C.name == 'nb_session':
     307        if C.name == 'nb_session_%s' % twist.notebook.port:
    307308            return C.value
    308309    return None  # not found
    309310   
  • sagenb/notebook/twist.py

    diff -r 8c1cb3615863 -r 79a1e5c34aa8 sagenb/notebook/twist.py
    a b  
    24642464                         'recovery': notebook.conf()['email'],
    24652465                         'sage_version':SAGE_VERSION}
    24662466        response = HTMLResponse(stream=template(os.path.join('html', 'login.html'), **template_dict))
    2467         response.headers.setHeader("set-cookie", [http_headers.Cookie('cookie_test', 'cookie_test')])
     2467        response.headers.setHeader("set-cookie", [http_headers.Cookie('cookie_test_%s' % notebook.port, 'cookie_test')])
    24682468        return response
    24692469
    24702470class FailedToplevel(Toplevel):
     
    25562556        # sign back in when she restarts her web browser
    25572557        # This works by setting an expiration date because without one the browser forgets the cookie.
    25582558        if 'remember' in request.args:
    2559             response.headers.setHeader("set-cookie", [http_headers.Cookie('nb_session', self.cookie, expires=(time.time() + 60 * 60 * 24 * 14)), http_headers.Cookie('cookie_test', self.cookie, expires=1)])
     2559            response.headers.setHeader("set-cookie", [http_headers.Cookie('nb_session_%s' % notebook.port, self.cookie, expires=(time.time() + 60 * 60 * 24 * 14)), http_headers.Cookie('cookie_test_%s' % notebook.port, self.cookie, expires=1)])
    25602560        else:
    2561             response.headers.setHeader("set-cookie", [http_headers.Cookie('nb_session', self.cookie), http_headers.Cookie('cookie_test', self.cookie, expires=1)])
     2561            response.headers.setHeader("set-cookie", [http_headers.Cookie('nb_session_%s' % notebook.port, self.cookie), http_headers.Cookie('cookie_test_%s' % notebook.port, self.cookie, expires=1)])
    25622562        return response
    25632563
    25642564setattr(UserToplevel, 'userchild_download_worksheets.zip', DownloadWorksheets)