Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CherryPy redirect to root

quick question: I have created a web server using CherryPy. It requires authentication for all pages, so my default handler returns the login page object. Due to the way that CherryPy handles the dispatches, somebody who requests:

localhost:80/a/b/c

would be redirected to:

localhost:80/a/b/login

however, I'd like all unauthenticated requests to be invoked from the root level, independent of the potential additional parameters added in the HTML request, e.G.:

localhost:80/a/b/c --> localhost:80/login

Currently I am solving this by returning a HTML based redirect:

'<meta http-equiv="REFRESH" content="0;url=/login">'

I feel this is a very unclean solution and would rather want to use a CherryPy based solution. I looked at cherrypy.HTTPRedirect and cherrypy.url, but I haven't found a way to make them work for this problem.

Any thoughts?

Thank you!

like image 310
Muppet Avatar asked Aug 19 '12 21:08

Muppet


1 Answers

You can specify the login page with a redirect: raise cherrypy.HTTPRedirect("/auth/login")

But, take a look here, there is a sample of how to write an authentication routine:

http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions

There is also an example of how to redirect the user back at the requested page after login.

like image 87
dcernahoschi Avatar answered Sep 29 '22 03:09

dcernahoschi