/tmp/tmp.e268ac7599ce14d8260c0ece9934088d/tmp.e268ac7599ce14d8260c0ece9934088d.rst:2: (WARNING/2) Title underline too short. ;-*-Doctest-*- ===========
Supports a configurable login sequence. On each login, the site manager is consulted for a series of steps to be completed before the user is logged in. If the steps are not completed, the user is not logged in.
The default configuration requires the user to change their password, then agree to a site policy before landing at their preferences page.
Use a browser.
>>> from Products.Five.testbrowser import Browser >>> browser = Browser() >>> browser.handleErrors = False
Setup the site policy.
>>> from Products.CMFTestCase import CMFTestCase >>> browser.open('http://nohost/plone/login_form') >>> browser.getControl( ... 'Login Name').value = CMFTestCase.portal_owner >>> browser.getControl( ... 'Password').value = CMFTestCase.default_password >>> browser.getControl('Log in').click()>>> browser.open('http://nohost/plone/edit_site_policy.html') >>> print browser.contents <!DOCTYPE html PUBLIC... <h3>Edit site policy</h3> ...</html>>>> browser.getControl('Site Policy').value = 'Foo site policy' >>> browser.getControl('Change').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <p>Updated on ...</p> ...</html>>>> browser.getLink('Log out').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <h1 class="documentFirstHeading">You are now logged out</h1> ...</html>
Setup user properties.
>>> self.loginAsPortalOwner() >>> member = self.portal.portal_membership.getMemberById( ... CMFTestCase.default_user) >>> member.setProperties( ... login_time='2000/01/01', must_change_password=1)
On initial login, a member must change thier password.
>>> browser.open('http://nohost/plone/login_form') >>> browser.getControl( ... 'Login Name').value = CMFTestCase.default_user >>> browser.getControl( ... 'Password').value = CMFTestCase.default_password >>> browser.getControl('Log in').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <p> Please use the form below to change your password. </p> ...</html>>>> from Products.CMFPlone.tests.PloneTestCase import ( ... default_password,) >>> browser.getControl('New password').value = 'foo_secret' >>> browser.getControl('Confirm password').value = 'foo_secret' >>> browser.getControl('Change Password').click()
Then they must agreee to the site policy if available.
>>> print browser.contents <!DOCTYPE html PUBLIC... <h3>Please accept the site policy</h3> ...</html>
Failure to agree will display an error.
>>> browser.getControl('Change').click()
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<h3>Please accept the site policy</h3>
<p>An error occurred.</p>
<p> There are <strong>1</strong> input errors. </p>...
<div class="label">
<label for="field.agreed" title="I agree to the terms and
conditions.">I agree</label>
</div>
Required input is missing.
...</html>
Once they agree, the user will land at their preferences edit page.
>>> browser.getControl('I agree').selected = True >>> browser.getControl('Change').click()>>> print browser.contents <!DOCTYPE html PUBLIC... <h1>Personal Preferences</h1> ...</html>>>> browser.getControl('Full name').value = 'Foo' >>> browser.getControl('Save').click()>>> print browser.contents <!DOCTYPE html PUBLIC... <a href="http://nohost/plone/portal_memberdata/test_user_1_" class="state-public navTreeCurrentItem" title=""> <img width="16" height="16" src="http://nohost/plone/user.gif" alt="Member" /> Foo </a>... <dl class="portalMessage info"> <dt>Info</dt> <dd>Changes saved.</dd> </dl> ...</html>
The user is now logged in everywhere.
>>> browser.open('http://nohost/plone')
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<a href="http://nohost/plone/logout">Log out</a>
...</html>
On subsequent logins, the member will proceed directly to the logged in page.
>>> browser.getLink('Log out').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <h1 class="documentFirstHeading">You are now logged out</h1> ...</html>>>> browser.getLink('Log in').click() >>> browser.getControl( ... 'Login Name').value = CMFTestCase.default_user >>> browser.getControl('Password').value = 'foo_secret' >>> browser.getControl('Log in').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <h1 class="documentFirstHeading">You are now logged in</h1> ...</html>
The steps are consulted on each login, so if conditions change, then the relevant steps must be completed on subsequent logins.
>>> browser.getLink('Log out').click()
>>> print browser.contents
<!DOCTYPE html PUBLIC...
<h1 class="documentFirstHeading">You are now logged out</h1>
...</html>
Update the site policy.
>>> browser.open('http://nohost/plone/login_form') >>> browser.getControl( ... 'Login Name').value = CMFTestCase.portal_owner >>> browser.getControl( ... 'Password').value = CMFTestCase.default_password >>> browser.getControl('Log in').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <h1 class="documentFirstHeading">You are now logged in</h1> ...</html>>>> browser.open('http://nohost/plone/edit_site_policy.html') >>> print browser.contents <!DOCTYPE html PUBLIC... <h3>Edit site policy</h3> ...</html>>>> browser.getControl('Site Policy').value = 'Bar site policy' >>> browser.getControl('Change').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <p>Updated on ...</p> ...</html>>>> browser.getLink('Log out').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <h1 class="documentFirstHeading">You are now logged out</h1> ...</html>
The site policy must be accepted again on next login.
>>> browser.getLink('Log in').click() >>> browser.getControl( ... 'Login Name').value = CMFTestCase.default_user >>> browser.getControl('Password').value = 'foo_secret' >>> browser.getControl('Log in').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <h3>Please accept the site policy</h3> ...</html>>>> browser.getControl('I agree').selected = True >>> browser.getControl('Change').click() >>> print browser.contents <!DOCTYPE html PUBLIC... <p>Updated on ...</p> ...</html>>>> browser.open('http://nohost/plone') >>> print browser.contents <!DOCTYPE html PUBLIC... <li> <a href="http://nohost/plone/logout">Log out</a> </li> ...</html>