8e82159dae9fcd36cce80e0898c64c0b1333c6f6
1 ##parameters=member_id='', given_name='', name='', member_email='', 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')
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')
15 validate_email
= ptool
.getProperty('validate_email')
16 is_anon
= mtool
.isAnonymousUser()
18 is_usermanager
= mtool
.checkPermission(ManageUsers
, mtool
)
20 form
= context
.REQUEST
.form
21 email_as_login
= bool(form
.get('email_as_login', True if context
.REQUEST
.method
== 'GET' else False))
25 password
= confirm
= rtool
.generatePassword()
28 ok
= context
.validatePassword(**form
)
32 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
['email_as_login'] = email_as_login
53 options
['password'] = is_newmember
and context
.REQUEST
.get('password', '') or ''
54 options
['portal_url'] = portal_url
55 options
['isAnon'] = is_anon
56 options
['isNewMember'] = is_newmember
57 options
['isOrdinaryMember'] = not (mtool
.isAnonymousUser() or is_newmember
)
58 options
['validate_email'] = validate_email
59 options
['isAnonRegistration'] = rtool
.getMode() == MODE_ANONYMOUS
60 options
['isReviewedRegistration'] = rtool
.getMode() == MODE_REVIEWED
64 target
= atool
.getActionInfo('user/logged_in')['url']
65 buttons
.append( {'name': 'login', 'value': 'Log in'} )
67 target
= atool
.getActionInfo('user/join')['url']
68 buttons
.append( {'name': 'add', 'value': _('Join')} )
69 options
['form'] = { 'action': target
,
70 'listButtonInfos': tuple(buttons
) }
72 return context
.join_template(**options
)