I have uploaded both my patch and the built EGG file (built and
patched against r156 from authkit SVN) to this group. Basically I
added a configuration option to the authkit's form authentication
method, that allows one to specify a template_error template that
shows up (instead of the normal template) when the user incorrectly
types in their username or password.
My sample configuration file, myapp.ini:
authkit.setup.method = form, cookie
authkit.form.authenticate.user.type =
myprjoect.auth.sqlalchemy_044:UsersFromDatabase
authkit.form.authenticate.user.data = myproject.model
authkit.form.authenticate.user.encrypt = authkit.users:md5
authkit.form.authenticate.user.encrypt.secret = some secret goes here
authkit.form.template.obj = myproject.controllers.auth:AuthLoginForm()
()
authkit.form.template_error.obj =
myproject.controllers.auth:AuthLoginForm(error=True)()
authkit.cookie.secret = another string goes here
authkit.cookie.name = myproject_authkt
authkit.cookie.signoutpath = /auth/signout/
Note especially the authkit.form.template_error element, this is what
has been added, and it works exactly the same way as the old
authkit.form.template element. I have also followed this chapter to
setup authkit in my pylons setup:
http://pylonsbook.com/alpha1/authentication_and_authorization
The code for my class AuthLoginForm() looks like:
class AuthLoginForm(object):
def __init__(self, error=False):
self.error = error
def __call__(self):
# Get the base directory, where myproject/templates and data/
templates
# are relative to
fileDir = os.path.dirname(os.path.abspath(__file__))
baseDir = os.path.realpath(os.path.join(fileDir,'../..'))
templatesDir = os.path.join(baseDir, 'myproject/templates')
moduleDir = os.path.join(baseDir, 'data/templates')
lookup = TemplateLookup(directories=[templatesDir],
module_directory=moduleDir)
loginForm = lookup.get_template('login_form.mako')
return loginForm.render(error=self.error)
Hope this helps. Oh, one last note, in your template file make sure
you have a '%s' (and only one) in there, as authkit substitutes the
form action method for it. So your template should have this in it
somewhere for your form to work (and you need to keep the form params
the same too):
<form action="${'%s'}" method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="authform" value="Sign In" />
</form>
-Mark