WAeUP portal authentication
***************************

:Test-Layer: functional

We need to protect most pieces of our portals from unauthenticated
access.

Therefore users have to login to access main functionality and they
are able to log out afterwards.

Before we can check access we have to create an app:

  >>> from waeup.app import University
  >>> root = getRootFolder()
  >>> u = University()
  >>> root['app'] = u

To make sure, we can 'watch' pages, we first have to initialize our
test browser:

  >>> from zope.testbrowser.testing import Browser
  >>> browser = Browser()
  >>> browser.handleErrors = False

Creating users (principals)
===========================

Before we can login, we have to provide a user (``principal`` in Zope
terms). On the API level we can so by looking up a
UserAuthenticationUtility named ``users``:

  >>> from zope.component import getUtility
  >>> from zope.app.authentication.interfaces import IAuthenticatorPlugin
  >>> authenticator = getUtility(IAuthenticatorPlugin, name=u'users')

This plugin also enables us to add new users. At least a username and
a password is required:

  >>> authenticator.addUser('bob', 'bobssecret')

We can also add complete `Account` objects. An `Account` stores the
user credentials and some metadata persistently:

  >>> from waeup.authentication import Account
  >>> alice = Account('alice', 'alicesecret')
  >>> authenticator.addAccount(alice)


Logging in via side bar
=======================

We can access the front page without restrictions:

  >>> browser.open('http://localhost/app')
  >>> print browser.headers['Status']
  200 Ok

There is a login form on the front page sidebar:

  >>> 'form.login' in browser.contents
  True

We use this form:

  >>> browser.getControl(name='form.login').value = 'grok'
  >>> browser.getControl(name='form.password').value = 'grok'
  >>> browser.getControl('Login').click()

