[Zope3-Users] Run starup code with zope 3.

Thierry Florac thierry.florac at onf.fr
Thu Feb 12 12:04:19 EST 2009


Le jeudi 12 février 2009 à 17:50 +0100, Sebastian Bartos a écrit :
> I'm struggling with some Zope 3 startup code. I registered a user like
> this for the Session Credentials plugin and login form stuff:
> 
> ...
> 
>     def create(self, data):
>         site = getSite()
>         sm = site.getSiteManager()
> 
>         if sm.has_key('auth'):
>             return "Site is already set up"
> 
>         pau = Pluggableauth()
>         sm['auth'] = pau
>         sm.registerUtility(pau, Iauth)
>         users = PrincipalFolder()
>         sm['auth']['Users'] = users
>         sm.registerUtility(users, IAuthenticatorPlugin, name="Users")
>         pau.authenticatorPlugins = (users.__name__, )
>         pau.credentialsPlugins = ("No Challenge if Authenticated",
>                                   "Session Credentials")
> 
>         user = InternalPrincipal("user", "foo", "user",
>                                  passwordManagerName="SHA1")
>         users["user"] = user
>        principalPermissionManager.grantAllPermissionsToPrincipal("user")


To run code automatically at application startup, I think that you
should have a look at the IDatabaseOpenedWithRootEvent (defined in
zope.app.appsetup.interfaces).
I use this event to check a set of persistent database utilities at
application startup, and it works fine.

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.florac at onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85



More information about the Zope3-users mailing list