d65c8efc1fc2e35009190ec8c5acf924ad465cfb
1 ##parameters=member_id='', given_name='', name='', member_email='', email_as_login='', password='', confirm='', add='', ajax=''
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')
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')
16 validate_email
= ptool
.getProperty('validate_email')
17 is_anon
= mtool
.isAnonymousUser()
19 is_usermanager
= mtool
.checkPermission(ManageUsers
, mtool
)
22 form
= context
.REQUEST
.form
26 password
= confirm
= rtool
.generatePassword()
29 ok
= context
.validatePassword(**form
)
33 member_id
= member_email
34 rtool
.addMember(id=member_id
, password
=password
,
35 properties
={'username': member_id
,
36 'given_name' : given_name
,
38 'email': member_email
})
40 rtool
.requestPasswordReset(member_id
, initial
=True)
41 context
.setStatus(True, _('Success!'))
44 except ValueError, errmsg
:
45 context
.setStatus(False, errmsg
)
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
63 target
= atool
.getActionInfo('user/logged_in')['url']
64 buttons
.append( {'name': 'login', 'value': 'Log in'} )
66 target
= atool
.getActionInfo('user/join')['url']
67 buttons
.append( {'name': 'add', 'value': _('Join')} )
68 options
['form'] = { 'action': target
,
69 'listButtonInfos': tuple(buttons
) }
71 return context
.join_template(**options
)