Changeset 4093 for waeup/branches/ulif-rewrite/src
- Timestamp:
- 26 Apr 2009, 13:08:49 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/authentication.txt
r4092 r4093 28 28 29 29 Before we can login, we have to provide a user (``principal`` in Zope 30 terms). On the API level we can so by looking up a 31 UserAuthenticationUtility named ``users``: 30 terms) with a password (and optional a title or description): 32 31 33 >>> from zope.component import getUtility 34 >>> from zope.app.authentication.interfaces import IAuthenticatorPlugin 35 >>> authenticator = getUtility(IAuthenticatorPlugin, name=u'users') 36 37 This plugin also enables us to add new users. At least a username and 38 a password is required: 39 40 >>> authenticator.addUser('bob', 'bobssecret') 32 >>> root['app'].users.addUser('bob', 'bobsecret', 33 ... title='Bob', description='A sample user') 41 34 42 35 We can also add complete `Account` objects. An `Account` stores the … … 45 38 >>> from waeup.authentication import Account 46 39 >>> alice = Account('alice', 'alicesecret') 47 >>> authenticator.addAccount(alice) 40 >>> root['app'].users.addAccount(alice) 41 42 See ``users.txt`` for details about the UserContainer we use here. 48 43 49 44 … … 62 57 True 63 58 59 >>> 'form.logout' in browser.contents 60 False 61 64 62 We use this form: 65 63 66 >>> browser.getControl(name='form.login').value = ' grok'67 >>> browser.getControl(name='form.password').value = ' grok'64 >>> browser.getControl(name='form.login').value = 'bob' 65 >>> browser.getControl(name='form.password').value = 'bobsecret' 68 66 >>> browser.getControl('Login').click() 69 67 68 Now the login form is gone. Instead we have the opportunity to logout: 69 70 >>> 'form.login' in browser.contents 71 False 72 73 >>> 'form.logout' in browser.contents 74 True 75 76 The user name is also displayed in the sidebar: 77 78 >>> 'bob' in browser.contents 79 80 >>> print browser.contents
Note: See TracChangeset for help on using the changeset viewer.