;--Doctest--

URL Authentication

Allows the application to specify a URL at which the user will be authenticated such that they will only be authenticated at that URL.

We'll demonstrate in a browser.

>>> from Products.Five.testbrowser import Browser
>>> browser = Browser()
>>> browser.handleErrors = False

To start with, the user is not authenticated at the specific URL or anywhere else.

>>> portal_url = self.portal.absolute_url()
>>> browser.open(portal_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/login_form">Log in</a>
</li>
...</html>
>>> members_url = self.portal.Members.absolute_url()
>>> browser.open(members_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/login_form">Log in</a>
</li>
...</html>

Designate an URL as authenticated for a session.

>>> from zope.publisher.interfaces import browser as ibrowser
>>> from grouparchy.login import testing
>>> self.portal.getSiteManager().registerAdapter(
...     testing.AuthMembersURL, provided=ibrowser.IBrowserView,
...     name=u'authMembersURL')
>>> browser.open(portal_url+'/@@authMembersURL')
>>> browser.contents
'test_user_1_ is logged in at http://nohost/plone/Members'

Now the user will be authenticated only at that URL.

>>> browser.open(portal_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/login_form">Log in</a>
</li>
...</html>
>>> browser.open(members_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/logout">Log out</a>
</li>
...</html>

And if they depart from that URL, the will once again be unauthenticated.

>>> browser.open(portal_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/login_form">Log in</a>
</li>
...</html>

Finally, the authentication for that URL can be removed.

>>> self.portal.getSiteManager().registerAdapter(
...     testing.UnauthURL, provided=ibrowser.IBrowserView,
...     name=u'unauthURL')
>>> browser.open(portal_url+'/@@unauthURL')
>>> browser.contents
'logged out'

Then the user is once again unauthenticated at that url.

>>> browser.open(portal_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/login_form">Log in</a>
</li>
...</html>
>>> browser.open(members_url)
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<li>
  <a href="http://nohost/plone/login_form">Log in</a>
</li>
...</html>