[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/ loginform can
be selected in FormChallenger plugin
robert rottermann
robert at redcor.ch
Tue Oct 12 10:22:09 EDT 2004
Log message for revision 28006:
loginform can be selected in FormChallenger plugin
changed form field name to :login and password
Changed:
U Zope3/trunk/src/zope/app/pas/browser/configure.zcml
U Zope3/trunk/src/zope/app/pas/browser/loginform.pt
U Zope3/trunk/src/zope/app/pas/browserplugins.py
U Zope3/trunk/src/zope/app/pas/challengeplugins.zcml
-=-
Modified: Zope3/trunk/src/zope/app/pas/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/pas/browser/configure.zcml 2004-10-12 13:51:02 UTC (rev 28005)
+++ Zope3/trunk/src/zope/app/pas/browser/configure.zcml 2004-10-12 14:22:07 UTC (rev 28006)
@@ -27,4 +27,10 @@
permission="zope.ManageServices"
menu="zmi_views" title="Edit" />
+ <editform
+ schema="..browserplugins.IFormChallengerLoginPageName"
+ label="Change login page name"
+ name="edit.html"
+ permission="zope.ManageServices"
+ menu="zmi_views" title="Edit" />
</zope:configure>
Modified: Zope3/trunk/src/zope/app/pas/browser/loginform.pt
===================================================================
--- Zope3/trunk/src/zope/app/pas/browser/loginform.pt 2004-10-12 13:51:02 UTC (rev 28005)
+++ Zope3/trunk/src/zope/app/pas/browser/loginform.pt 2004-10-12 14:22:07 UTC (rev 28006)
@@ -6,14 +6,13 @@
</head>
<body><div metal:fill-slot="body">
<p i18n:translate="">Please provide Login Information</p>
- <h1 tal:content="request/REFERER" />
<form action="" method="post"
- tal:attributes="action request/REFERER"
+ tal:attributes="action request/camefrom"
>
<div class="row">
<div class="label" i18n:translate="">User Name</div>
<div class="field">
- <input type="text" name="username"/>
+ <input type="text" name="login"/>
</div>
</div>
Modified: Zope3/trunk/src/zope/app/pas/browserplugins.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/browserplugins.py 2004-10-12 13:51:02 UTC (rev 28005)
+++ Zope3/trunk/src/zope/app/pas/browserplugins.py 2004-10-12 14:22:07 UTC (rev 28006)
@@ -17,16 +17,19 @@
$Id$
"""
-from zope.interface import implements
+from zope.interface import implements, Interface
+from zope.schema import TextLine
from persistent import Persistent
from zope.app.component import hooks
from zope.app.container.contained import Contained
from zope.app.traversing.browser.absoluteurl import absoluteURL
from zope.app import zapi
from zope.app.session.interfaces import ISession
+from urllib import urlencode
from zope.app.pas.interfaces import IExtractionPlugin, IChallengePlugin
+
class SessionExtractor(Persistent, Contained):
""" session-based credential extractor.
@@ -47,17 +50,17 @@
If the session does not contain the credentials check
the request for form variables.
- >>> request = createTestRequest(username='scott', password='tiger')
+ >>> request = createTestRequest(login='scott', password='tiger')
>>> se.extractCredentials(request)
- {'username': 'scott', 'password': 'tiger'}
+ {'login': 'scott', 'password': 'tiger'}
>>> request = createTestRequest()
>>> sessionData = Session(request)['pas_credentials']
- >>> sessionData['username'] = 'scott'
+ >>> sessionData['login'] = 'scott'
>>> sessionData['password'] = 'tiger'
>>> se.extractCredentials(request)
- {'username': 'scott', 'password': 'tiger'}
+ {'login': 'scott', 'password': 'tiger'}
"""
implements(IExtractionPlugin)
@@ -66,16 +69,30 @@
sessionData = ISession(request)['pas_credentials']
if not sessionData:
# check for form data
- un = request.get('username', None)
- pw = request.get('password', None)
- if un and pw:
- sessionData['username'] = un
- sessionData['password'] = pw
+ login = request.get('login', None)
+ password = request.get('password', None)
+ if login and password:
+ sessionData['login'] = login
+ sessionData['password'] = password
else:
return None
- return {'username': sessionData['username'],
+ return {'login': sessionData['login'],
'password': sessionData['password']}
+
+
+class IFormChallengerLoginPageName(Interface):
+ """HTTP Basic Auth Realm
+
+ Represents the realm string that is used during basic HTTP authentication
+ """
+
+ loginpagename = TextLine(title=u'loginpagename',
+ description=u'Name of the login form used by challenger',
+ required=True,
+ default=u'/@@loginForm.html')
+
+
class FormChallenger(Persistent, Contained):
""" Query the user for credentials using a browser form.
@@ -97,15 +114,13 @@
The response's headers should now contain the URL to redirect to.
>>> headers = response.getHeaders()
>>> headers['Location']
- 'http://127.0.0.1/login.html?REFERER=http://127.0.0.1'
+ 'http://127.0.0.1/@@loginForm.html?camefrom=http%3A%2F%2F127.0.0.1'
"""
- implements(IChallengePlugin)
+ implements(IChallengePlugin, IFormChallengerLoginPageName)
- def getLoginPage(self):
- """ return configurable login page """
- return '/@@loginForm.html'
+ loginpagename = '/@@loginForm.html'
def challenge(self, request, response):
""" Response shuold redirect to login page cause Credebtials
@@ -116,7 +131,7 @@
camefrom = request.getURL()
url = absoluteURL(site, request)
- url += self.getLoginPage() + '?REFERER=' + camefrom
+ url += self.loginpagename + '?' + urlencode({'camefrom' :camefrom})
response.redirect(url)
return True
Modified: Zope3/trunk/src/zope/app/pas/challengeplugins.zcml
===================================================================
--- Zope3/trunk/src/zope/app/pas/challengeplugins.zcml 2004-10-12 13:51:02 UTC (rev 28005)
+++ Zope3/trunk/src/zope/app/pas/challengeplugins.zcml 2004-10-12 14:22:07 UTC (rev 28006)
@@ -56,4 +56,16 @@
permission="zope.ManageServices"
/>
+ <localUtility class=".browserplugins.FormChallenger">
+
+ <implements
+ interface="zope.app.annotation.interfaces.IAttributeAnnotatable" />
+
+ <require
+ permission="zope.ManageServices"
+ interface=".browserplugins.IFormChallengerLoginPageName"
+ set_schema=".browserplugins.IFormChallengerLoginPageName" />
+
+ </localUtility>
+
</configure>
More information about the Zope3-Checkins
mailing list