I’m new to AuthKit, and I wanted to override the method authkit.authenticate.valid_password for the form way of handling authentication. But could not figure out a good way of doing this. It appears that they only way overriding this method is to use the forward handler, but then again I had AuthKit working more or less the way I wanted using the form handler.
So how do you go about overriding one method in a library that you’re using? Well in Python you can use the wraptools module. This allows you to override a method using decorators. For example,
@replaces(authkit.authenticate.valid_password)
def valid_password(environ, username, password):
try:
# validate the username/password
return True
except YourLoginException:
return False
February 22, 2010 at 12:46 pm |
I have been tackling the same problem.
I was unable to get your solution working due to my own inexperience with Python.
It is possible to put in the pylons development.ini file a reference to a custom valid_password method with the option
authkit.form.authenticate.function=trackmgr.controllers.Login:valid_password
where Login is a file called Login.py and :valid_password is the method name.
This example was found on http://groups.google.com/group/authkit/browse_thread/thread/5405fba6649fecab