X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-web.git/blobdiff_plain/b7f6fe4999dff15a49995f70bdafc95949c15116..542183dd43e3d9c9260b2ce1313126b7f6535f6c:/code/view.py diff --git a/code/view.py b/code/view.py index 87a527b..d15d53f 100644 --- a/code/view.py +++ b/code/view.py @@ -82,6 +82,14 @@ def require_login(): cherrypy.tools.require_login = cherrypy.Tool('on_start_resource', require_login, priority=150) +def require_POST(): + """If the request isn't a POST request, raise 405 Method Not Allowed""" + if cherrypy.request.method != "POST": + raise cherrypy.HTTPError(405, + "You must submit this request with POST") + +cherrypy.tools.require_POST = cherrypy.Tool('on_start_resource', require_POST, priority=150) + def remote_user_login(): """Get the current user based on the SSL or GSSAPI environment variables""" environ = cherrypy.request.wsgi_environ @@ -104,7 +112,8 @@ cherrypy.tools.remote_user_login = cherrypy.Tool('on_start_resource', remote_use def invirtwebstate_init(): """Initialize the cherrypy.request.state object from Invirt""" - cherrypy.request.state = State(cherrypy.request.login) + if not hasattr(cherrypy.request, "state"): + cherrypy.request.state = State(cherrypy.request.login) cherrypy.tools.invirtwebstate = cherrypy.Tool('on_start_resource', invirtwebstate_init, priority=100)