[Checkins] SVN: z3c.authenticator/trunk/ - Implemented z3c.form
prefix support in SessionCredentialsPlugin. Now there is
Roger Ineichen
roger at projekt01.ch
Sat Aug 2 21:03:44 EDT 2008
Log message for revision 89243:
- Implemented z3c.form prefix support in SessionCredentialsPlugin. Now there is
an option called prefixes which can be used for define a list of used
z3c.form prefixes. This makes it simpler for supporting different forms and
adjust the credential extraction.
- Added test for this new feature
Changed:
U z3c.authenticator/trunk/CHANGES.txt
U z3c.authenticator/trunk/src/z3c/authenticator/credential.py
U z3c.authenticator/trunk/src/z3c/authenticator/interfaces.py
-=-
Modified: z3c.authenticator/trunk/CHANGES.txt
===================================================================
--- z3c.authenticator/trunk/CHANGES.txt 2008-08-03 00:12:31 UTC (rev 89242)
+++ z3c.authenticator/trunk/CHANGES.txt 2008-08-03 01:03:43 UTC (rev 89243)
@@ -2,16 +2,22 @@
CHANGES
=======
+
Version 0.5.2dev (unreleased)
-----------------------------
-- ...
+- feature: implemented z3c.form prefix support in SessionCredentialsPlugin. Now
+ there is an option called prefixes which can be used for define a list of
+ used z3c.form prefixes. This makes it simpler for supporting different forms
+ and adjust the credential extraction.
+
Version 0.5.1 (2008-04-16)
--------------------------
- Cleanup imports and adjust dependencies
+
Version 0.5.0 (2008-04-16)
--------------------------
Modified: z3c.authenticator/trunk/src/z3c/authenticator/credential.py
===================================================================
--- z3c.authenticator/trunk/src/z3c/authenticator/credential.py 2008-08-03 00:12:31 UTC (rev 89242)
+++ z3c.authenticator/trunk/src/z3c/authenticator/credential.py 2008-08-03 01:03:43 UTC (rev 89243)
@@ -234,13 +234,34 @@
Now we build a request that uses the new fields:
- >>> request = TestRequest(my_new_login_field='luke', my_new_password_field='the_force')
+ >>> request = TestRequest(my_new_login_field='luke',
+ ... my_new_password_field='the_force')
The plugin now extracts the credentials information from these new fields:
>>> plugin.extractCredentials(request)
{'login': 'luke', 'password': 'the_force'}
+ We can also set prefixes for the fields from which the credentials are
+ extracted:
+
+ >>> plugin.loginfield = "login"
+ >>> plugin.passwordfield = "password"
+ >>> plugin.prefixes = ['form.widgets.']
+
+ Now we build a request that uses the new fields. Note that we need a
+ browser request which provides a form for this test since we can't setup
+ our prefixes.
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> request = TestRequest(form={'form.widgets.login':'harry',
+ ... 'form.widgets.password':'potter'})
+
+ The plugin now extracts the credentials information from these new fields:
+
+ >>> plugin.extractCredentials(request)
+ {'login': 'harry', 'password': 'potter'}
+
Finally, we clear the session credentials using the logout method.
If the given logout argument doesn't provide IHTTPRequest the
result will always be False:
@@ -263,6 +284,7 @@
challengeProtocol = None
+ prefixes = []
loginpagename = 'loginForm.html'
loginfield = 'login'
passwordfield = 'password'
@@ -275,6 +297,10 @@
sessionData = session.get('z3c.authenticator.credential.session')
login = request.get(self.loginfield, None)
password = request.get(self.passwordfield, None)
+ # support z3c.form prefixes
+ for prefix in self.prefixes:
+ login = request.get(prefix + self.loginfield, login)
+ password = request.get(prefix + self.passwordfield, password)
credentials = None
if login and password:
Modified: z3c.authenticator/trunk/src/z3c/authenticator/interfaces.py
===================================================================
--- z3c.authenticator/trunk/src/z3c/authenticator/interfaces.py 2008-08-03 00:12:31 UTC (rev 89242)
+++ z3c.authenticator/trunk/src/z3c/authenticator/interfaces.py 2008-08-03 01:03:43 UTC (rev 89243)
@@ -419,6 +419,16 @@
class IBrowserFormChallenger(zope.interface.Interface):
"""A challenger that uses a browser form to collect user credentials."""
+ prefixes = zope.schema.List(
+ title=u'Form prefixes',
+ description=u'List of prefixes used in different login forms',
+ value_type = zope.schema.TextLine(
+ title=u'Form prefix',
+ description=u'Form prefix',
+ missing_value=u'',
+ required=True),
+ default=[])
+
loginpagename = zope.schema.TextLine(
title=u'Loginpagename',
description=u"""Name of the login form used by challenger.
More information about the Checkins
mailing list