[Zope3-checkins] SVN: Zope3/branches/3.2/ Backported from trunk: svn merge -r 67210:67211

Florian Lindner Florian.Lindner at xgm.de
Tue Apr 25 17:32:25 EDT 2006


Log message for revision 67611:
  Backported from trunk: svn merge -r 67210:67211
  
  Change the session credentials plugin to make it configurable in which fields it looks for the credentials.
  

Changed:
  U   Zope3/branches/3.2/doc/CHANGES.txt
  U   Zope3/branches/3.2/src/zope/app/authentication/session.py

-=-
Modified: Zope3/branches/3.2/doc/CHANGES.txt
===================================================================
--- Zope3/branches/3.2/doc/CHANGES.txt	2006-04-25 21:06:04 UTC (rev 67610)
+++ Zope3/branches/3.2/doc/CHANGES.txt	2006-04-25 21:32:23 UTC (rev 67611)
@@ -10,6 +10,9 @@
 
     Bug fixes
 
+      - Change the session credentials plugin to make it configurable in which
+	fields it looks for the credentials.
+
       - Fixed issue 590: zope.app.mail could send multiple copies of emails on
         ConflictErrors, and it was also rate limited to 1 email per second when
         you used QueuedMailDelivery.

Modified: Zope3/branches/3.2/src/zope/app/authentication/session.py
===================================================================
--- Zope3/branches/3.2/src/zope/app/authentication/session.py	2006-04-25 21:06:04 UTC (rev 67610)
+++ Zope3/branches/3.2/src/zope/app/authentication/session.py	2006-04-25 21:32:23 UTC (rev 67611)
@@ -83,12 +83,22 @@
     """A challenger that uses a browser form to collect user credentials."""
 
     loginpagename = TextLine(
-        title=u'loginpagename',
+        title=u'Loginpagename',
         description=u"""Name of the login form used by challenger.
 
         The form must provide 'login' and 'password' input fields.
         """,
         default=u'loginForm.html')
+    
+    loginfield = TextLine(
+        title=u'Loginfield',
+        description=u"Field of the login page in which is looked for the login user name.",
+        default=u"login")
+        
+    passwordfield = TextLine(
+        title=u'Passwordfield',
+        description=u"Field of the login page in which is looked for the password.",
+        default=u"password")
 
 
 class SessionCredentialsPlugin(Persistent, Contained):
@@ -142,6 +152,20 @@
 
       >>> plugin.extractCredentials(TestRequest())
       {'login': 'harry', 'password': 'hirsch'}
+      
+    We can also change the fields from which the credentials are extracted:
+    
+      >>> plugin.loginfield = "my_new_login_field"
+      >>> plugin.passwordfield = "my_new_password_field"
+      
+    Now we build a request that uses the new fields:
+    
+      >>> 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'}
 
     Finally, we clear the session credentials using the logout method:
 
@@ -154,6 +178,8 @@
     implements(ICredentialsPlugin, IBrowserFormChallenger)
 
     loginpagename = 'loginForm.html'
+    loginfield = 'login'
+    passwordfield = 'password'
 
     def extractCredentials(self, request):
         """Extracts credentials from a session if they exist."""
@@ -162,8 +188,8 @@
 
         sessionData = ISession(request)[
             'zope.app.authentication.browserplugins']
-        login = request.get('login', None)
-        password = request.get('password', None)
+        login = request.get(self.loginfield, None)
+        password = request.get(self.passwordfield, None)
         if login and password:
             credentials = SessionCredentials(login, password)
             sessionData['credentials'] = credentials



More information about the Zope3-Checkins mailing list