Re: automatic portal member creation

Aroldo Souza-Leite <[email protected]>
Newsgroups gmane.comp.web.zope.cps.devel
Message-ID <[email protected]>
Hi Marco,

here is the script  (thanks to Joachim for the hint):


Regards,

Aroldo.

------------------------------<PythonScript>-------------------------------------------------


#PythonScript register_dummy_in_cps_portal
# deletes 'dummy' portal member (if exists)
# registers a portal member with id 'dummy'

# you probably gave another id to your cps site
# change 'miscellaneous' below to your cps site id
cps_site_id = 'miscellaneous'

zope_cps_site_root = getattr(container,cps_site_id) # the cps site as a
Zope object
cps_registration_tool = zope_cps_site_root['portal_registration'] # this
avoids acquisition ambiguities
cps_membership_tool = zope_cps_site_root['portal_membership'] # same here


############################################################################
# Deletes dummy
# The argument of deleteMembers is a tuple (...,...,...,)
# A tuple with one element is written ('element',),
# and has one extra comma at the end of the list.

deleteMembers = cps_membership_tool.deleteMembers # this checks if the
tool has this method
deleteMembers(('dummy',))
print 'dummy deleted (if existed)'


#############################################################################
# registers dummy

dummy_properties =  {'username':'dummy',
                                     'password':'123456',
                                     'sn':u'Imbécile',
                                     'givenName':u'Très',
                                     'email':u'[email protected]'}
dummy_roles = ('Member', 'Contributor') # etc; it should be at least
('Member',) (with an extra comma at the end!)
addMember = cps_registration_tool.addMember # this checks if the tool
has this method
try:
   addMember(id = 'dummy',
             password = '123456',
             roles =dummy_roles,
             properties = dummy_properties
            )
except Exception, e:
   print 'adding dummy failed'
   print str(e)
else:
   print "dummy added (if it did't exist yet)"

########################################################################

return printed


----------------------------------------</PythonScript>----------------------------------------------------

_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.