[Zope3-checkins]
SVN: Zope3/trunk/src/zope/app/pas/browserplugins.py
adapted chalenge to use absoluteURL, adapted tests
robert rottermann
robert at redcor.ch
Mon Oct 11 08:11:51 EDT 2004
Log message for revision 27970:
adapted chalenge to use absoluteURL, adapted tests
Changed:
U Zope3/trunk/src/zope/app/pas/browserplugins.py
-=-
Modified: Zope3/trunk/src/zope/app/pas/browserplugins.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/browserplugins.py 2004-10-11 12:08:10 UTC (rev 27969)
+++ Zope3/trunk/src/zope/app/pas/browserplugins.py 2004-10-11 12:11:51 UTC (rev 27970)
@@ -21,7 +21,7 @@
from persistent import Persistent
from zope.app.component import hooks
from zope.app.container.contained import Contained
-from zope.app.traversing.browser.interfaces import IAbsoluteURL
+from zope.app.traversing.browser.absoluteurl import absoluteURL
from zope.app import zapi
from zope.app.session.interfaces import ISession
@@ -42,7 +42,8 @@
No credentials available:
>>> request = createTestRequest()
- >>> se.extractCredentials(request)
+ >>> se.extractCredentials(request) is None
+ True
If the session does not contain the credentials check
the request for form variables.
@@ -61,8 +62,10 @@
implements(IExtractionPlugin)
def extractCredentials(self, request):
+ """ return credentials from session, request or None """
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:
@@ -78,7 +81,11 @@
""" Query the user for credentials using a browser form.
First we need a request and a response.
+
+ >>> from zope.app.tests.setup import placefulSetUp
+ >>> site = placefulSetUp(True)
+
>>> from zope.publisher.browser import TestRequest
>>> request = TestRequest()
>>> response = request.response
@@ -91,20 +98,26 @@
The response's headers should now contain the URL to redirect to.
>>> headers = response.getHeaders()
>>> headers['Location']
- 'http://127.0.0.1'
+ 'http://127.0.0.1/login.html?REFERER=http://127.0.0.1'
"""
implements(IChallengePlugin)
+
+ def getLoginPage(self):
+ """ return configurable login page """
+ return '/login.html'
def challenge(self, request, response):
""" Response shuold redirect to login page cause Credebtials
could not have been extracted.
"""
site = hooks.getSite()
- #url = zapi.getView(site, zapi.name(site), request, providing=IAbsoluteURL,
- # context=site)
- url = request.getApplicationURL()
+
+ camefrom = request.getURL()
+
+ url = absoluteURL(site, request)
+ url += self.getLoginPage() + '?REFERER=' + camefrom
response.redirect(url)
return True
More information about the Zope3-Checkins
mailing list