Logging in to the client after forgetting your password
=======================================================

Before we can start we must set up our test environment by
creating an dummy survey.

>>> from euphorie.client.tests.utils import addSurvey
>>> from euphorie.client.tests.utils import addAccount
>>> from Products.Five.testbrowser import Browser
>>> xml_survey="""\
... <sector xmlns="http://xml.simplon.biz/euphorie/survey/1.0">
...    <title>Sector title</title>
...    <survey>
...      <title>Survey title</title>
...    </survey>
...  </sector>"""
>>> self.loginAsPortalOwner()
>>> addSurvey(portal, xml_survey)
>>> self.logout()
>>> account = addAccount()
>>> browser = Browser()


First login attempt
-------------------
We start our story when the user tries to look at the surveys for his country.
Note that we bypass the country selection stage to make sure our test stays in
an English user interface. When we try to look at the login we are prompted for
a login:

>>> browser.open(portal.client.nl.absolute_url())
>>> "@@login" in browser.url
True

Lets try to login:

>>> browser.getControl(name="__ac_name").value="jane@example.com"
>>> browser.getControl(name="__ac_password:utf8:ustring").value="john"
>>> browser.getControl(name="next", index=0).click()
>>> browser.contents
'...Your login name and/or password were entered incorrectly...'

Oops. Our login failed.


Request a password reminder
---------------------------

All is not lost! Lets try the password reminder feature.

>>> def send(self, *args, **kw):
...     pass
>>> from Products.MailHost.mailer import SMTPMailer
>>> original_send=SMTPMailer.send
>>> SMTPMailer.send=send

>>> browser.getLink("request an email reminder").click()
>>> browser.getControl(name="loginname").value="jane@example.com"
>>> browser.getControl(name="next").click()

>>> SMTPMailer.send=original_send

We are now back at the login form:

>>> browser.url
'http://nohost/plone/client/nl/@@login...'


Logging in again
----------------

After checking our email for the password reminder we can try to login again:

>>> browser.getControl(name="__ac_name").value="jane@example.com"
>>> browser.getControl(name="__ac_password:utf8:ustring").value=u"Øle".encode("utf-8")
>>> browser.getControl(name="next", index=0).click()

And we are now indeed at the session screen:

>>> browser.url
'http://nohost/plone/client/nl'
>>> browser.contents
'...Session...'

