Author: | Gustavo Narea. |
---|---|
Latest release: | 1.0.6 |
Overview
repoze.who-friendlyform is a repoze.who plugin which provides a collection of developer-friendly form plugins, although for the time being such a collection has only one item.
The minimum requirement is repoze.who, and you can install both with easy_install:
easy_install repoze.who-friendlyform
RedirectingFormPlugin-like form plugin with more features.
It is like RedirectingFormPlugin, but provides us with the following features:
You should keep in mind that if you’re using a post-login or a post-logout page, that page will receive the referrer URL as a query string variable whose name is “came_from”.
Forms can be submitted with any encoding (non-ASCII credentials are supported) and ISO-8859-1 (aka “Latin-1”) is the default one.
Parameters: |
|
---|
The login counter variable’s name will be set to __logins if login_counter_name equals None.
Changed in version 1.0.1: Added the charset argument.
When you use this plugin, you would implement a controller action for logins, like this one:
# You have to adapt this function to the way things work in your framework:
def login(request):
login_counter = request.environ['repoze.who.logins']
if login_counter > 0:
display_message("Wrong credentials", status="error")
came_from = request.params.get("came_from") or "/"
return render("login.html", login_counter=login_counter, came_from=came_from)
Where the “login.html” template is defined as:
<!-- Adapt this code to your templating engine -->
<form action="/login_handler?came_from={{ came_from }}&__logins={{ login_counter }}"
method="POST">
<label>Username: <input type="text" name="login"/></label>
<label>Password: <input type="password" name="password"/></label>
<input type="submit" value="Login"/>
</form>
A controller action for post-logins could look like:
# You have to adapt this function to the way things work in your framework:
def welcome_back(request):
identity = request.environ.get("repoze.who.identity")
came_from = request.params.get('came_from', '') or "/"
if identity:
# Login succeeded
userid = identity['repoze.who.userid']
display_message('Welcome back, %s!' % userid, status="success")
destination = came_from
else:
# Login failed
login_counter = request.environ['repoze.who.logins'] + 1
destination = "/login?came_from=%s&__logins=%s" % (came_from, login_counter)
return Redirect(destination)
A controller action for post-logouts could look like:
# You have to adapt this function to the way things work in your framework:
def see_you_later(request):
display_message("We hope to see you soon!", status="success")
came_from = request.params.get('came_from', '') or "/"
return Redirect(came_from)
The prefered place to ask questions is the Repoze mailing list or the #repoze IRC channel. Bugs reports and feature requests should be sent to the issue tracker of the Repoze project.
The development mainline is available at the following Subversion repository:
http://svn.repoze.org/whoplugins/whofriendlyforms/trunk/