Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1614

Show
Ignore:
Timestamp:
02/07/07 15:29:04
Author:
lawouach
Message:

Implemented a login attribute for the request and answered #653

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/_cprequest.py

    r1612 r1614  
    305305    to the script_name ('mount point') of the application which is 
    306306    handling this request.""" 
     307 
     308    login = None 
     309    login__doc = """ 
     310    When authentication is used during the request processing this is 
     311    set to 'False' if it failed and to the 'username' value if it succeeded. 
     312    The default 'None' implies that no authentication happened.""" 
    307313     
    308314    app = None 
  • trunk/cherrypy/lib/auth.py

    r1418 r1614  
    2727        if httpauth.checkResponse(ah, password, method=cherrypy.request.method, 
    2828                                  encrypt=encrypt): 
     29            cherrypy.request.login = ah["username"] 
    2930            return True 
    3031     
     32        cherrypy.request.login = False 
    3133    return False 
    3234 
  • trunk/cherrypy/lib/cptools.py

    r1462 r1614  
    229229            return True 
    230230        else: 
    231             cherrypy.session[self.session_key] = username 
     231            cherrypy.session[self.session_key] = cherrypy.request.login = username 
    232232            self.on_login(username) 
    233233            raise cherrypy.HTTPRedirect(from_page or "/") 
     
    239239        sess[self.session_key] = None 
    240240        if username: 
     241            cherrypy.request.login = None 
    241242            self.on_logout(username) 
    242243        raise cherrypy.HTTPRedirect(from_page) 
     
    256257                del cherrypy.response.headers["Content-Length"] 
    257258            return True 
    258          
     259        cherrypy.request.login = username 
    259260        self.on_check(username) 
    260261     
  • trunk/cherrypy/test/test_httpauth.py

    r1468 r1614  
    1515    class DigestProtected: 
    1616        def index(self): 
    17             return "This is protected by Digest auth." 
     17            return "Hello %s, you've been authorized." % cherrypy.request.login 
    1818        index.exposed = True 
    1919 
    2020    class BasicProtected: 
    2121        def index(self): 
    22             return "This is protected by Basic auth." 
     22            return "Hello %s, you've been authorized." % cherrypy.request.login 
    2323        index.exposed = True 
    2424 
     
    5858        self.getPage('/basic/', [('Authorization', 'Basic dGVzdDp0ZXN0')]) 
    5959        self.assertStatus('200 OK') 
    60         self.assertBody('This is protected by Basic auth.'
     60        self.assertBody("Hello test, you've been authorized."
    6161 
    6262    def testDigest(self): 
     
    112112        self.getPage('/digest/', [('Authorization', auth)]) 
    113113        self.assertStatus('200 OK') 
    114         self.assertBody('This is protected by Digest auth.'
     114        self.assertBody("Hello test, you've been authorized."
    115115             
    116116if __name__ == "__main__": 
  • trunk/cherrypy/test/test_sessionauthenticate.py

    r1324 r1614  
    88    def check(username, password): 
    99        # Dummy check_username_and_password function 
    10         if username != 'login' or password != 'password': 
     10        if username != 'test' or password != 'password': 
    1111            return u'Wrong login/password' 
    1212     
     
    1919         
    2020        def index(self): 
    21             return "Hi, you are logged in" 
     21            return "Hi %s, you are logged in" % cherrypy.request.login 
    2222        index.exposed = True 
    2323     
     
    3737         
    3838        # setup credentials 
    39         login_body = 'username=login&password=password&from_page=/' 
     39        login_body = 'username=test&password=password&from_page=/' 
    4040         
    4141        # attempt a login 
     
    4545        # get the page now that we are logged in 
    4646        self.getPage('/', self.cookies) 
    47         self.assertBody('Hi, you are logged in') 
     47        self.assertBody('Hi test, you are logged in') 
    4848         
    4949        # do a logout 

Hosted by WebFaction

Log in as guest/cpguest to create tickets