579a38f0049a1ec1f4162be893244316c1862ebb
[Plinn.git] / Products / Plinn / skins / custom_generic / join_form.py
1 ##parameters=b_start=0, member_id='', given_name='', name='', member_email='', password='', confirm='', send_password='', add='', ajax=''
2 ##
3 from Products.CMFCore.utils import getToolByName
4 from Products.CMFDefault.permissions import ManageUsers
5 from Products.Plinn.RegistrationTool import MODE_ANONYMOUS, MODE_REVIEWED
6 from Products.Plinn.utils import translate
7 def _(message) : return translate(message, context).encode('utf-8')
8
9
10 mtool = getToolByName(script, 'portal_membership')
11 ptool = getToolByName(script, 'portal_properties')
12 rtool = getToolByName(script, 'portal_registration')
13 atool = getToolByName(script, 'portal_actions')
14 utool = getToolByName(script, 'portal_url')
15 portal_url = utool()
16 validate_email = ptool.getProperty('validate_email')
17 is_anon = mtool.isAnonymousUser()
18 is_newmember = False
19 is_usermanager = mtool.checkPermission(ManageUsers, mtool)
20
21
22 form = context.REQUEST.form
23 if add and \
24 context.validatePassword(**form) and \
25 context.members_add_control(**form) and \
26 context.setRedirect(atool, 'user/join', b_start=b_start, ajax=ajax):
27 return
28
29 options = {}
30
31 if context.REQUEST.get('portal_status_message', '') == 'Success!':
32 is_anon = False
33 is_newmember = True
34
35 options['member_id'] = member_id
36 options['given_name'] = given_name
37 options['name'] = name
38 options['member_email'] = member_email
39 options['password'] = is_newmember and context.REQUEST.get('password', '') or ''
40 options['send_password'] = send_password
41 options['portal_url'] = portal_url
42 options['isAnon'] = is_anon
43 options['isAnonOrUserManager'] = is_anon or is_usermanager
44 options['isNewMember'] = is_newmember
45 options['isOrdinaryMember'] = not (is_anon or is_newmember or is_usermanager)
46 options['validate_email'] = validate_email
47 options['isAnonRegistration'] = rtool.getMode() == MODE_ANONYMOUS
48 options['isReviewedRegistration'] = rtool.getMode() == MODE_REVIEWED
49
50 buttons = []
51 if is_newmember:
52 target = atool.getActionInfo('user/logged_in')['url']
53 buttons.append( {'name': 'login', 'value': 'Log in'} )
54 else:
55 target = atool.getActionInfo('user/join')['url']
56 buttons.append( {'name': 'add', 'value': _('Join')} )
57 options['form'] = { 'action': target,
58 'listButtonInfos': tuple(buttons) }
59 options['ajax']=ajax
60 return context.join_template(**options)