Back to index

plone3  3.1.7
members_add_control.py
Go to the documentation of this file.
00001 ##parameters=member_id, password, member_email, send_password=False, **kw
00002 ##title=Add a member
00003 ##
00004 from Products.CMFCore.utils import getUtilityByInterfaceName
00005 from Products.CMFCore.utils import getToolByName
00006 from Products.CMFDefault.permissions import ManageUsers
00007 from Products.CMFDefault.utils import Message as _
00008 
00009 mtool = getToolByName(script, 'portal_membership')
00010 ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
00011 rtool = getToolByName(script, 'portal_registration')
00012 
00013 try:
00014     rtool.addMember( id=member_id, password=password,
00015                      properties={'username': member_id,
00016                                  'email': member_email},
00017                      REQUEST=context.REQUEST)
00018 except ValueError, errmsg:
00019     return context.setStatus(False, errmsg)
00020 else:
00021     if ptool.getProperty('validate_email') or send_password:
00022         rtool.registeredNotify(member_id, REQUEST=context.REQUEST)
00023     if mtool.checkPermission(ManageUsers, mtool):
00024         return context.setStatus(True, _(u'Member registered.'))
00025     else:
00026         return context.setStatus(False, _(u'Success!'), is_newmember=True)