3badc16ddf09cd55d10b256da88f0603aaa35cb1
[Plinn.git] / Products / Plinn / skins / custom_generic / join_form.py
1 ##parameters=member_id='', given_name='', name='', member_email='', password='', confirm='', add='', came_from='', 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 mtool = getToolByName(script, 'portal_membership')
10 ptool = getToolByName(script, 'portal_properties')
11 rtool = getToolByName(script, 'portal_registration')
12 atool = getToolByName(script, 'portal_actions')
13 utool = getToolByName(script, 'portal_url')
14 portal_url = utool()
15 validate_email = ptool.getProperty('validate_email')
16 is_anon = mtool.isAnonymousUser()
17 is_newmember = False
18 is_usermanager = mtool.checkPermission(ManageUsers, mtool)
19
20 form = context.REQUEST.form
21 email_as_login = bool(form.get('email_as_login', True if context.REQUEST.method == 'GET' else False))
22
23 if add :
24 if validate_email :
25 password = confirm = rtool.generatePassword()
26 ok = True
27 else :
28 ok = context.validatePassword(**form)
29 if ok :
30 try :
31 if email_as_login :
32 member_id = member_email
33
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, came_from=came_from)
41 context.setStatus(True, _('Success!'))
42 is_newmember = True
43 is_anon = False
44 except ValueError, errmsg:
45 raise
46 context.setStatus(False, errmsg)
47
48 options = {}
49 options['member_id'] = member_id
50 options['given_name'] = given_name
51 options['name'] = name
52 options['member_email'] = member_email
53 options['email_as_login'] = email_as_login
54 options['password'] = is_newmember and context.REQUEST.get('password', '') or ''
55 options['portal_url'] = portal_url
56 options['isAnon'] = is_anon
57 options['isNewMember'] = is_newmember
58 options['isOrdinaryMember'] = not (mtool.isAnonymousUser() or is_newmember)
59 options['validate_email'] = validate_email
60 options['isAnonRegistration'] = rtool.getMode() == MODE_ANONYMOUS
61 options['isReviewedRegistration'] = rtool.getMode() == MODE_REVIEWED
62 options['came_from'] = came_from
63
64 buttons = []
65 if is_newmember:
66 target = atool.getActionInfo('user/logged_in')['url']
67 buttons.append( {'name': 'login', 'value': 'Log in'} )
68 else:
69 target = atool.getActionInfo('user/join')['url']
70 buttons.append( {'name': 'add', 'value': _('Join')} )
71 options['form'] = { 'action': target,
72 'listButtonInfos': tuple(buttons) }
73 options['ajax']=ajax
74 return context.join_template(**options)