Changeset 2391


Ignore:
Timestamp:
Aug 9, 2009, 6:45:23 PM (15 years ago)
Author:
quentin
Message:

Add list method, require authentication for it, and add a hello world via mako

Location:
package_branches/invirt-web/cherrypy/code
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • package_branches/invirt-web/cherrypy/code/main.py

    r2390 r2391  
    5252        super(self.__class__,self).__init__()
    5353        connect()
     54        self._cp_config['tools.require_login.on'] = True
    5455
    5556    @cherrypy.expose
     57    @cherrypy.tools.mako(filename="/list.mako")
     58    def list(self, username):
     59        """Handler for list requests."""
     60        checkpoint.checkpoint('Getting list dict')
     61        d = getListDict(username, state)
     62        checkpoint.checkpoint('Got list dict')
     63        return templates.list(searchList=[d])
     64    index=list
     65
     66    @cherrypy.expose
     67    @cherrypy.tools.mako(filename="/helloworld.mako")
    5668    def helloworld(self):
    57         return "Hello world!"
     69        return {}
     70        return "Hello world!\nYour request: "+repr(dir(cherrypy.request))
     71    helloworld._cp_config['tools.require_login.on'] = False
    5872
    5973def pathSplit(path):
     
    229243    return d
    230244
    231 def listVms(username, state, path, fields):
    232     """Handler for list requests."""
    233     checkpoint.checkpoint('Getting list dict')
    234     d = getListDict(username, state)
    235     checkpoint.checkpoint('Got list dict')
    236     return templates.list(searchList=[d])
    237 
    238245def vnc(username, state, path, fields):
    239246    """VNC applet page.
     
    638645    raise RuntimeError("test of the emergency broadcast system")
    639646
    640 mapping = dict(list=listVms,
     647mapping = dict(#list=listVms,
    641648               vnc=vnc,
    642649               command=command,
  • package_branches/invirt-web/cherrypy/code/view.py

    r2385 r2391  
    6868cherrypy.tools.jsonify = cherrypy.Tool('before_finalize', jsonify_tool_callback, priority=30)
    6969
     70def external_remote_user_login():
     71    pass
     72
     73def require_login():
     74    """If the user isn't logged in, raise 403 with an error."""
     75    if cherrypy.request.login is False:
     76        raise cherrypy.HTTPError(403,
     77            "You are not authorized to access that resource")
     78
     79cherrypy.tools.require_login = cherrypy.Tool('on_start_resource', require_login)
     80
    7081class View(object):
    7182    _cp_config = {'tools.mako.directories': [os.path.join(os.path.dirname(__file__),'templates')]}
Note: See TracChangeset for help on using the changeset viewer.