I wrote a forms authentication plugin for CherryPy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

I wrote a forms authentication plugin for CherryPy

Darryl Agostinelli
How do I go about submitting a tool for review to be included into the
code base?

I wrote a first-class forms authentication plugin for CherryPy.
Here's how it works:

In your config, you'd add these lines:

tools.auth_forms.on = True
tools.auth_forms.login_url = "/path/to/my/login"
tools.auth_forms.session_key = "STARTREKISGREAT"

In your login page handler, you'd do something like this:

        @cherrypy.expose
        def login(self, username=None, password=None, returnUrl="/"):

                if username is None or password is None:
                        return .... login screen template .render(returnUrl = returnUrl)

                error_msg = AuthenticationDB.check_credentials(username, password)
                if error_msg:
                        return .... login screen template .render(returnUrl = returnUrl,
errorMsg = error_msg, username = username)
                else:
                        HTTPFormsAuthentication.login_and_redirect(username, returnUrl)

        @cherrypy.expose
        def logout(self, returnUrl="/"):
                HTTPFormsAuthentication.logout()
                raise cherrypy.HTTPRedirect(returnUrl)

That's it!  I can send the plugin to whomever.

-DarrylA

--
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/cherrypy-devel?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: I wrote a forms authentication plugin for CherryPy

Sylvain Hellegouarch


On Sun, Sep 11, 2011 at 4:38 AM, DarrylA <[hidden email]> wrote:
How do I go about submitting a tool for review to be included into the
code base?

I wrote a first-class forms authentication plugin for CherryPy.
Here's how it works:

In your config, you'd add these lines:

tools.auth_forms.on = True
tools.auth_forms.login_url = "/path/to/my/login"
tools.auth_forms.session_key = "STARTREKISGREAT"

In your login page handler, you'd do something like this:

       @cherrypy.expose
       def login(self, username=None, password=None, returnUrl="/"):

               if username is None or password is None:
                       return .... login screen template .render(returnUrl = returnUrl)

               error_msg = AuthenticationDB.check_credentials(username, password)
               if error_msg:
                       return .... login screen template .render(returnUrl = returnUrl,
errorMsg = error_msg, username = username)
               else:
                       HTTPFormsAuthentication.login_and_redirect(username, returnUrl)

       @cherrypy.expose
       def logout(self, returnUrl="/"):
               HTTPFormsAuthentication.logout()
               raise cherrypy.HTTPRedirect(returnUrl)

That's it!  I can send the plugin to whomever.



Hi Darry,

We seldom add new tools to the core because this means more maintaining and we are too few. Usually we advise contributors to add their code to the tools wiki http://tools.cherrypy.org/ which acts as a more central point for those contributions.

Thanks, 
--
- Sylvain
http://www.defuze.org
http://twitter.com/lawouach

--
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/cherrypy-devel?hl=en.