============================
Password Confirmation Widget
============================

The password confirmation widget allows you to upload a new password to the 
server. Additional to the original widget, it offers a confirmation field
where the given password must be confirmed. The "password" type of the "INPUT"
element is described here:

http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#edef-INPUT

As for all widgets, the password widget must provide the new ``IWidget``
interface:

  >>> from zope.interface.verify import verifyClass
  >>> import zope.component
  >>> from zope.i18n.negotiator import Negotiator
  >>> from zope.i18n.interfaces import INegotiator
  >>> from z3c.form.interfaces import IWidget
  >>> from z3c.form.interfaces import INPUT_MODE
  >>> from j01.form import interfaces
  >>> from j01.form.widget.password import PasswordConfirmationWidget

  >>> zope.component.provideUtility(Negotiator(), INegotiator, '')

  >>> verifyClass(IWidget, PasswordConfirmationWidget)
  True

The widget can be instantiated only using the request:

  >>> from z3c.form.testing import TestRequest
  >>> request = TestRequest()

  >>> widget = PasswordConfirmationWidget(request)

Before rendering the widget, one has to set the name and id of the widget:

  >>> widget.id = 'widget-id'
  >>> widget.name = 'widget.name'

We also need to register the template for the widget:

  >>> import zope.component
  >>> from zope.pagetemplate.interfaces import IPageTemplate
  >>> from z3c.form.widget import WidgetTemplateFactory

  >>> import os
  >>> import j01.form.widget
  >>> def getPath(filename):
  ...     return os.path.join(os.path.dirname(j01.form.widget.__file__),
  ...     filename)

  >>> zope.component.provideAdapter(
  ...     WidgetTemplateFactory(getPath('password_confirmation_input.pt'), 'text/html'),
  ...     (None, None, None, None, interfaces.IPasswordConfirmationWidget),
  ...     IPageTemplate, name=INPUT_MODE)

If we render the widget we get a simple input element:

  >>> print(widget.render())
  <input type="password" id="widget-id" name="widget.name"
         class="passwordWidget" />
  <BLANKLINE>
  <div class="labelPasswordConfirmation">
    <label for="widget-id-confirm">
      <span>Password confirmation</span>
    </label>
  </div>
  <BLANKLINE>
  <input type="password" id="widget-id-confirm"
         name="widget.name.confirm" class="passwordWidget" />
  <BLANKLINE>

Even when we set a value on the widget, it is not displayed for security
reasons:

  >>> widget.value = 'password'
  >>> print(widget.render())
  <input type="password" id="widget-id" name="widget.name"
         class="passwordWidget" />
  <BLANKLINE>
  <div class="labelPasswordConfirmation">
    <label for="widget-id-confirm">
      <span>Password confirmation</span>
    </label>
  </div>
  <BLANKLINE>
  <input type="password" id="widget-id-confirm"
         name="widget.name.confirm" class="passwordWidget" />
  <BLANKLINE>

Let's now make sure that we can extract user entered data from a widget:

  >>> widget.request = TestRequest(form={'widget.name': 'password'})
  >>> widget.update()
  >>> widget.extract()
  'password'

If nothing is found in the request, the default is returned:

  >>> widget.request = TestRequest()
  >>> widget.update()
  >>> widget.extract()
  <NO_VALUE>
