[4090] | 1 | User for the WAeUP portal |
---|
| 2 | ************************* |
---|
| 3 | |
---|
[5140] | 4 | .. :doctest: |
---|
| 5 | .. :layer: waeup.sirp.testing.WAeUPSIRPUnitTestLayer |
---|
[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 | User Containers |
---|
| 14 | =============== |
---|
| 15 | |
---|
| 16 | We can create a user container which will hold the useraccounts for |
---|
| 17 | us: |
---|
| 18 | |
---|
[4920] | 19 | >>> from waeup.sirp.users import UserContainer |
---|
[4090] | 20 | >>> myusers = UserContainer() |
---|
| 21 | |
---|
| 22 | We can add users, just by passing a name, a password, and (optionally) |
---|
| 23 | a title and a description: |
---|
| 24 | |
---|
| 25 | >>> myusers.addUser('bob', 'bobssecret') |
---|
| 26 | |
---|
| 27 | Now, Bob is in the container: |
---|
| 28 | |
---|
| 29 | >>> list(myusers) |
---|
| 30 | [u'bob'] |
---|
| 31 | |
---|
| 32 | We can get Bob's account: |
---|
| 33 | |
---|
| 34 | >>> bob = myusers['bob'] |
---|
| 35 | >>> bob |
---|
[4920] | 36 | <waeup.sirp.authentication.Account object at 0x...> |
---|
[4090] | 37 | |
---|
| 38 | >>> bob.name |
---|
| 39 | 'bob' |
---|
| 40 | |
---|
| 41 | >>> bob.title |
---|
| 42 | 'bob' |
---|
| 43 | |
---|
| 44 | >>> bob.description |
---|
| 45 | 'bob' |
---|
| 46 | |
---|
| 47 | As we did not give a title nor description, the name was taken instead |
---|
| 48 | for these values. The password, however, is stored encoded: |
---|
| 49 | |
---|
| 50 | >>> bob.password |
---|
| 51 | '...15aca8166' |
---|
| 52 | |
---|
| 53 | Remark: that we can tell the last chars of the 'encrypted' password, |
---|
| 54 | means, that the encryption is broken or at least waeker as it should |
---|
| 55 | be. |
---|
| 56 | |
---|
| 57 | XXX: We could provide a stronger (correct) SHA encryption. |
---|
| 58 | |
---|
| 59 | We can delete users: |
---|
| 60 | |
---|
| 61 | >>> myusers.delUser('alice') |
---|
| 62 | |
---|
| 63 | The container won't complain, although there is no ``alice`` stored |
---|
| 64 | yet. But we can really delete users: |
---|
| 65 | |
---|
| 66 | >>> myusers.delUser('bob') |
---|
| 67 | >>> list(myusers) |
---|
| 68 | [] |
---|