Christian Lueck wrote:

>How do I get the PAUtility? (or the several PAUs?)
>paus =
>returns no pau at all, neither in the context of the root-folder, nor in
>the context of the local site called 'subfolder'. len(paus) is allways 0.

This is still a miracle to me and I would still like to learn.
But thanks to Tom's advice I was able to write a view which adds new
principals to the ZMI-registered principal folder plugin. It is possible
to get the principal folder plugin without getting the PAU before:

>>> from import Debugger
>>> debugger = Debugger('var/Data.fs', 'etc/site.zcml')
>>> root = debugger.root()
>>> from import setSite
>>> setSite(root)

still zero PAUs:

>>> from import IPluggableAuthentication
>>> paus = zapi.getAllUtilitiesRegisteredFor(IPluggableAuthentication)
>>> print len(paus)

but the principal folder plugin which I named 'users' in the ZMI is there:

>>> from import IAuthenticatorPlugin
>>> apus = zapi.getAllUtilitiesRegisteredFor(IAuthenticatorPlugin)
>>> print len(apus)
>>> for apu in apus:
...     plugin = apu
>>> plugin.__name__

So I wrote the above mentioned view which could be a substitute for
Example 19.2.7 of Philipp's book. -- Hmm, I'm really not happy with it,
but it's a first step...
Note that it makes use of the ZMI-registered 'new style' principal
folder instead of 19.2.2. It does not work with the cookie based login
of Chapter 19.1 -- don't ask me why (may be due to my config).

from zope.i18nmessageid import MessageIDFactory
from import removeSecurityProxy

from import zapi
from import BrowserView
from import UserError
from import IAuthenticatorPlugin
from import InternalPrincipal
from import IPrincipalRoleManager

_ = MessageIDFactory('paradigm')

#from paradigm.userdb.interfaces import ISignupPrincipalSource

principal_source_name = 'users'

class SignUpView(BrowserView):

    def _getPrincipalSource(self):
            ps = zapi.getUtility(IAuthenticatorPlugin,
                                 context = self.context)
        except ComponentLookupError:
            raise UserError(_("Signup requires a Principal Source Folder."))
        return ps

    def signUp(self, login, title, password, confirmation):
        # check confirmation
        if confirmation != password:
            raise UserError(_(u"Password and confirmation didn't match"))

        # instantiate a new principal
        newprincipal = InternalPrincipal(login=login,

        # get principal source and add newprincipal to it
        principal_source = self._getPrincipalSource()
        if login in principal_source:
            raise UserError(_(u"This login has already been choosen."))
            principal_source[login] = newprincipal
        except ValueError:
            raise UserError(_(u"There already exists a principal with
this login. Please choose a different one."))

        # hm, this works only with 19.2.2
        #role_manager = IPrincipalRoleManager(self.context)
        #role_manager = removeSecurityProxy(role_manger)
        #for role in principal_source.signup_roles:
        #    role_manager.assignRoleToPrincipal(role,

        # redirect to next url

Zope3-users mailing list

Reply via email to