3badc16ddf09cd55d10b256da88f0603aaa35cb1
1 ##parameters=member_id='', given_name='', name='', member_email='', password='', confirm='', add='', came_from='', 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, came_from
=came_from
)
41 context
.setStatus(True, _('Success!'))
44 except ValueError, errmsg
:
46 context
.setStatus(False, errmsg
)
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
66 target
= atool
.getActionInfo('user/logged_in')['url']
67 buttons
.append( {'name': 'login', 'value': 'Log in'} )
69 target
= atool
.getActionInfo('user/join')['url']
70 buttons
.append( {'name': 'add', 'value': _('Join')} )
71 options
['form'] = { 'action': target
,
72 'listButtonInfos': tuple(buttons
) }
74 return context
.join_template(**options
)