Ignore:
Timestamp:
5 Jul 2013, 10:38:08 (11 years ago)
Author:
uli
Message:

Change set_session_cookie API to be more consistent with other funcs. Minor restructuring.

Location:
main/waeup.cas/trunk/waeup/cas
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.cas/trunk/waeup/cas/server.py

    r10403 r10405  
    8787
    8888
    89 def set_session_cookie(response, db):
     89def set_session_cookie(db, response):
    9090    """Create a session cookie (ticket granting cookie) on `response`.
    9191
     
    165165    resp = Response(html)
    166166    if not sso:
    167         resp = set_session_cookie(resp, db)
     167        resp = set_session_cookie(db, resp)
    168168    return resp
    169169
     
    212212        valid_lt = check_login_ticket(self.db, req.POST.get('lt'))
    213213        tgc = check_session_cookie(self.db, req.cookies.get('cas-tgc', None))
    214         if username and password and valid_lt or tgc:
     214        if tgc:
     215            if service:
     216                return login_redirect_service(self.db, service)
     217            else:
     218                return login_success_no_service(
     219                    self.db, 'You logged in already.', True)
     220        if username and password and valid_lt:
    215221            # act as credentials acceptor
    216             if tgc:
    217                 cred_ok, reason = True, ''
    218                 if not service:
    219                     msg = 'You logged in already.'
    220             else:
    221                 cred_ok, reason = self.auth.check_credentials(
    222                     username, password)
     222            cred_ok, reason = self.auth.check_credentials(
     223                username, password)
    223224            if cred_ok:
    224225                if service is None:
    225226                    # show logged-in screen
    226                     sso = (tgc is not None)
    227                     return login_success_no_service(self.db, msg, sso)
     227                    return login_success_no_service(self.db, msg, False)
    228228                else:
    229229                    # safely redirect to service given
  • main/waeup.cas/trunk/waeup/cas/tests/test_server.py

    r10404 r10405  
    289289        # make sure we can add session cookies to responses
    290290        db = DB('sqlite:///')
    291         resp = set_session_cookie(Response(), db)
     291        resp = set_session_cookie(db, Response())
    292292        assert 'Set-Cookie' in resp.headers
    293293        cookie = resp.headers['Set-Cookie']
Note: See TracChangeset for help on using the changeset viewer.