Back to index

plone3  3.1.7
join_form.py
Go to the documentation of this file.
00001 ##parameters=b_start=0, member_id='', member_email='', password='', confirm='', send_password='', add='', cancel=''
00002 ##
00003 from Products.CMFCore.utils import getUtilityByInterfaceName
00004 from Products.CMFCore.utils import getToolByName
00005 from Products.CMFDefault.permissions import ManageUsers
00006 from Products.CMFDefault.utils import decode
00007 from Products.CMFDefault.utils import Message as _
00008 
00009 atool = getToolByName(script, 'portal_actions')
00010 mtool = getToolByName(script, 'portal_membership')
00011 ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
00012 utool = getToolByName(script, 'portal_url')
00013 portal_url = utool()
00014 validate_email = ptool.getProperty('validate_email')
00015 is_anon = mtool.isAnonymousUser()
00016 is_newmember = False
00017 is_usermanager = mtool.checkPermission(ManageUsers, mtool)
00018 
00019 
00020 form = context.REQUEST.form
00021 if add and \
00022         context.validatePassword(**form) and \
00023         context.members_add_control(**form) and \
00024         context.setRedirect(atool, 'user/join', b_start=b_start):
00025     return
00026 elif cancel and \
00027         context.setRedirect(atool, 'global/manage_members', b_start=b_start):
00028     return
00029 
00030 
00031 options = {}
00032 
00033 if context.REQUEST.get('is_newmember', False) == True:
00034     is_anon = False
00035     is_newmember = True
00036 
00037 options['title'] = is_usermanager and _(u'Register Member') \
00038                                   or _(u'Become a Member')
00039 options['member_id'] = member_id
00040 options['member_email'] = member_email
00041 options['password'] = is_newmember and context.REQUEST.get('password', '') or ''
00042 options['send_password'] = send_password
00043 options['portal_url'] = portal_url
00044 options['isAnon'] = is_anon
00045 options['isAnonOrUserManager'] = is_anon or is_usermanager
00046 options['isNewMember'] = is_newmember
00047 options['isOrdinaryMember'] = not (is_anon or is_newmember or is_usermanager)
00048 options['validate_email'] = validate_email
00049 
00050 buttons = []
00051 if is_newmember:
00052     target = atool.getActionInfo('user/logged_in')['url']
00053     buttons.append( {'name': 'login', 'value': _(u'Log in')} )
00054 else:
00055     target = atool.getActionInfo('user/join')['url']
00056     buttons.append( {'name': 'add', 'value': _(u'Register')} )
00057     buttons.append( {'name': 'cancel', 'value': _(u'Cancel')} )
00058 options['form'] = { 'action': target,
00059                     'listButtonInfos': tuple(buttons) }
00060 
00061 return context.join_template(**decode(options, script))