[7819] | 1 | User container for the Kofa |
---|
[7321] | 2 | *************************** |
---|
[4090] | 3 | |
---|
[5140] | 4 | .. :doctest: |
---|
[7819] | 5 | .. :layer: waeup.kofa.testing.KofaUnitTestLayer |
---|
[4090] | 6 | |
---|
| 7 | Before we can start, we need some password managers available: |
---|
| 8 | |
---|
| 9 | >>> from zope.app.authentication.placelesssetup import ( |
---|
| 10 | ... PlacelessSetup) |
---|
| 11 | >>> PlacelessSetup().setUp() |
---|
| 12 | |
---|
| 13 | We can create a user container which will hold the useraccounts for |
---|
| 14 | us: |
---|
| 15 | |
---|
[7811] | 16 | >>> from waeup.kofa.userscontainer import UsersContainer |
---|
[7172] | 17 | >>> myusers = UsersContainer() |
---|
[4090] | 18 | |
---|
| 19 | We can add users, just by passing a name, a password, and (optionally) |
---|
| 20 | a title and a description: |
---|
| 21 | |
---|
| 22 | >>> myusers.addUser('bob', 'bobssecret') |
---|
| 23 | |
---|
| 24 | Now, Bob is in the container: |
---|
| 25 | |
---|
| 26 | >>> list(myusers) |
---|
| 27 | [u'bob'] |
---|
| 28 | |
---|
| 29 | We can get Bob's account: |
---|
| 30 | |
---|
| 31 | >>> bob = myusers['bob'] |
---|
| 32 | >>> bob |
---|
[7811] | 33 | <waeup.kofa.authentication.Account object at 0x...> |
---|
[4090] | 34 | |
---|
| 35 | >>> bob.name |
---|
| 36 | 'bob' |
---|
| 37 | |
---|
| 38 | >>> bob.title |
---|
| 39 | 'bob' |
---|
| 40 | |
---|
| 41 | >>> bob.description |
---|
| 42 | |
---|
| 43 | |
---|
[7197] | 44 | As we did not give a title, the name was taken instead |
---|
| 45 | for title (but not for description). The password, however, is stored encoded: |
---|
| 46 | |
---|
[4090] | 47 | >>> bob.password |
---|
[8343] | 48 | '{SSHA}...' |
---|
[4090] | 49 | |
---|
| 50 | We can delete users: |
---|
| 51 | |
---|
| 52 | >>> myusers.delUser('alice') |
---|
| 53 | |
---|
| 54 | The container won't complain, although there is no ``alice`` stored |
---|
| 55 | yet. But we can really delete users: |
---|
| 56 | |
---|
| 57 | >>> myusers.delUser('bob') |
---|
| 58 | >>> list(myusers) |
---|
| 59 | [] |
---|