0e07d03153d80b0da2508029c4efb0159c311175
[Plinn.git] / Products / Plinn / skins / custom_generic / join_form.py
1 ##parameters=member_id='', given_name='', name='', member_email='', email_as_login='', password='', confirm='', 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
24 if add :
25 if validate_email :
26 password = confirm = rtool.generatePassword()
27 else :
28 ok = context.validatePassword(**form)
29 try :
30 if email_as_login :
31 member_id = member_email
32 rtool.addMember(id=member_id, password=password,
33 properties={'username': member_id,
34 'given_name' : given_name,
35 'name' : name,
36 'email': member_email})
37 context.setStatus(True, _('Success!'))
38 except ValueError, errmsg:
39 context.setStatus(False, errmsg)
40
41
42
43 # if add and \
44 # context.validatePassword(**form) and \
45 # context.members_add_control(**form) and \
46 # context.setRedirect(atool, 'user/join', b_start=b_start, ajax=ajax):
47 # return
48
49 options = {}
50
51 if context.REQUEST.get('portal_status_message', '') == 'Success!':
52 is_anon = False
53 is_newmember = True
54
55 options['member_id'] = member_id
56 options['given_name'] = given_name
57 options['name'] = name
58 options['member_email'] = member_email
59 options['password'] = is_newmember and context.REQUEST.get('password', '') or ''
60 options['portal_url'] = portal_url
61 options['isAnon'] = is_anon
62 options['isNewMember'] = is_newmember
63 options['validate_email'] = validate_email
64 options['isAnonRegistration'] = rtool.getMode() == MODE_ANONYMOUS
65 options['isReviewedRegistration'] = rtool.getMode() == MODE_REVIEWED
66
67 buttons = []
68 if is_newmember:
69 target = atool.getActionInfo('user/logged_in')['url']
70 buttons.append( {'name': 'login', 'value': 'Log in'} )
71 else:
72 target = atool.getActionInfo('user/join')['url']
73 buttons.append( {'name': 'add', 'value': _('Join')} )
74 options['form'] = { 'action': target,
75 'listButtonInfos': tuple(buttons) }
76 options['ajax']=ajax
77 return context.join_template(**options)