d65c8efc1fc2e35009190ec8c5acf924ad465cfb
[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 ok = True
28 else :
29 ok = context.validatePassword(**form)
30 if ok :
31 try :
32 if email_as_login :
33 member_id = member_email
34 rtool.addMember(id=member_id, password=password,
35 properties={'username': member_id,
36 'given_name' : given_name,
37 'name' : name,
38 'email': member_email})
39 if validate_email :
40 rtool.requestPasswordReset(member_id, initial=True)
41 context.setStatus(True, _('Success!'))
42 is_newmember = True
43 is_anon = False
44 except ValueError, errmsg:
45 context.setStatus(False, errmsg)
46
47 options = {}
48 options['member_id'] = member_id
49 options['given_name'] = given_name
50 options['name'] = name
51 options['member_email'] = member_email
52 options['password'] = is_newmember and context.REQUEST.get('password', '') or ''
53 options['portal_url'] = portal_url
54 options['isAnon'] = is_anon
55 options['isNewMember'] = is_newmember
56 options['isOrdinaryMember'] = not (mtool.isAnonymousUser() or is_newmember)
57 options['validate_email'] = validate_email
58 options['isAnonRegistration'] = rtool.getMode() == MODE_ANONYMOUS
59 options['isReviewedRegistration'] = rtool.getMode() == MODE_REVIEWED
60
61 buttons = []
62 if is_newmember:
63 target = atool.getActionInfo('user/logged_in')['url']
64 buttons.append( {'name': 'login', 'value': 'Log in'} )
65 else:
66 target = atool.getActionInfo('user/join')['url']
67 buttons.append( {'name': 'add', 'value': _('Join')} )
68 options['form'] = { 'action': target,
69 'listButtonInfos': tuple(buttons) }
70 options['ajax']=ajax
71 return context.join_template(**options)