Users ContainerΒΆ

Before we can start, we need some password managers available:

>>> from zope.app.authentication.placelesssetup import (
...   PlacelessSetup)
>>> PlacelessSetup().setUp()

We can create a user container which will hold the useraccounts for us:

>>> from waeup.kofa.userscontainer import UsersContainer
>>> myusers = UsersContainer()

We can add users, just by passing a name, a password, and (optionally) a title and a description:

>>> myusers.addUser('bob', 'bobssecret')

Now, Bob is in the container:

>>> list(myusers)
[u'bob']

We can get Bob’s account:

>>> bob = myusers['bob']
>>> bob
<waeup.kofa.authentication.Account object at 0x...>
>>> bob.name
'bob'
>>> bob.title
'bob'
>>> bob.description

As we did not give a title, the name was taken instead for title (but not for description). The password, however, is stored encoded:

>>> bob.password
'{SSHA}...'

We can export user accounts:

>>> from waeup.kofa.userscontainer import UserExporter
>>> import os
>>> import tempfile
>>> workdir = tempfile.mkdtemp()
>>> outfile = os.path.join(workdir, 'myoutput.csv')
>>> exporter = UserExporter()
>>> site = {'users':myusers}
>>> exporter.export_all(site, outfile)
>>> result = open(outfile, 'rb').read()
>>> 'name,title,public_name,description,email,phone,roles,local_roles,password' in result
True
>>> '{SSHA}' in result
True

We can delete users:

>>> myusers.delUser('alice')

The container won’t complain, although there is no alice stored yet. But we can really delete users:

>>> myusers.delUser('bob')
>>> list(myusers)
[]

Clean up:

>>> import shutil
>>> shutil.rmtree(workdir)