[Zope3-Users] assigning roles to principals on
AuthenticatedPrincipalCreated event
Hassan Alirezaei
hassan at isi.imi.i.u-tokyo.ac.jp
Thu Sep 21 10:54:33 EDT 2006
Hello zope3-users,
I am trying to do make easy user registrations for my website. but I am
having problems assigning roles to the principals automatically.
the question is WHEN should I assign these roles to the new principals?
which is the standard procedure?
right now I am doing :
1. User accounts (InternalPrincipal) are created.
2. The first time the user logs in a role with id="isi.member" will be
assigned to it on the whole site so the user receives membership
permissions.
*********************************************configure.zcml*****************************************************
<subscriber
handler=".userhome.UserLoggedIn"
for="zope.app.authentication.interfaces.IAuthenticatedPrincipalCreated"
/>
*********************************************userhome.py********************************************************
class UserLoggedIn(object):
def __init__(self, event):
userAnno=zapi.getUtility(IPrincipalAnnotationUtility,
'ISIUserAnnotation')
annotations=userAnno.getAnnotations(event.principal)
if annotations.get('user_home') is None:
print "***************RGISTERING ANNOTATIONS*****************"
annotations['user_home'] = Folder()
annotations['user_home']['register'] = PersistentDict()
annotations['user_home']['personal'] = Person()
annotations['user_home']['personal'].first='hassan'
annotations['user_home']['personal'].last='alirezaei'
annotations['user_home']['testing'] = "TESTING THE NEW USER"
siteroot=getSite()
prm=IPrincipalRoleManager(siteroot)
print "******************for %s *******************" %siteroot
prm.assignRoleToPrincipal('isi.member', event.principal)
******************************************************************************************************
getSite() gives me <ISI.isi.isi.isi object at 0xb659eb2c> but when i
go to this object (my main site root) and change to "Grant" from
zmi_actions menu the role is still unset for the user.
any help is highly appreciated. it is very much possible I am doing the
hard way to perform the task.
Thank you in advance!
Hass
More information about the Zope3-users
mailing list