[797] | 1 | ## Controller Python Script "register" |
---|
| 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind state=state |
---|
| 7 | ##bind subpath=traverse_subpath |
---|
| 8 | ##parameters=password='password', password_confirm='password_confirm', came_from_prefs=None |
---|
| 9 | ##title=Register a User |
---|
| 10 | ## |
---|
| 11 | |
---|
[1871] | 12 | from Products.CMFPlone import PloneMessageFactory as _ |
---|
[797] | 13 | from ZODB.POSException import ConflictError |
---|
| 14 | |
---|
| 15 | REQUEST = context.REQUEST |
---|
| 16 | |
---|
| 17 | portal = context.portal_url.getPortalObject() |
---|
| 18 | portal_registration = context.portal_registration |
---|
| 19 | |
---|
| 20 | username = REQUEST['username'] |
---|
| 21 | |
---|
| 22 | password=REQUEST.get('password') or portal_registration.generatePassword() |
---|
| 23 | |
---|
| 24 | # This is a temporary work-around for an issue with CMF not properly |
---|
| 25 | # reserving some existing ids (FSDV skin elements, for example). Until |
---|
| 26 | # this is fixed in the CMF we can at least fail nicely. See |
---|
| 27 | # http://dev.plone.org/plone/ticket/2982 and http://plone.org/collector/3028 |
---|
| 28 | # for more info. (rohrer 2004-10-24) |
---|
| 29 | try: |
---|
| 30 | portal_registration.addMember(username, password, properties=REQUEST, REQUEST=context.REQUEST) |
---|
| 31 | except AttributeError: |
---|
[1871] | 32 | state.setError('username', _(u'The login name you selected is already in use or is not valid. Please choose another.')) |
---|
| 33 | context.plone_utils.addPortalMessage(_(u'Please correct the indicated errors.'), 'error') |
---|
[797] | 34 | return state.set(status='failure') |
---|
| 35 | |
---|
| 36 | if portal.validate_email or REQUEST.get('mail_me', 0): |
---|
| 37 | try: |
---|
| 38 | portal_registration.registeredNotify(username) |
---|
| 39 | except ConflictError: |
---|
| 40 | raise |
---|
| 41 | except Exception, err: |
---|
| 42 | |
---|
| 43 | # TODO registerdNotify calls into various levels. Lets catch all |
---|
| 44 | # exceptions. Should not fail. They cant CHANGE their password ;-) |
---|
| 45 | # We should notify them. |
---|
| 46 | # |
---|
| 47 | # (MSL 12/28/03) We also need to delete the just made member and return to the join_form. |
---|
| 48 | state.set(came_from='login_success') |
---|
| 49 | if portal.validate_email: |
---|
| 50 | context.acl_users.userFolderDelUsers([username,], REQUEST=context.REQUEST) |
---|
[1871] | 51 | msg = _(u'status_fatal_password_mail', |
---|
[797] | 52 | default=u'Failed to create your account: we were unable to send your password to your email address: ${address}', |
---|
| 53 | mapping={u'address' : str(err)}) |
---|
| 54 | context.plone_utils.addPortalMessage(msg, 'error') |
---|
| 55 | return state.set(status='failure') |
---|
| 56 | else: |
---|
[1871] | 57 | msg = _(u'status_nonfatal_password_mail', |
---|
[797] | 58 | default=u'You account has been created, but we were unable to send your password to your email address: ${address}', |
---|
| 59 | mapping={u'address' : str(err)}) |
---|
| 60 | context.plone_utils.addPortalMessage(msg, 'error') |
---|
| 61 | |
---|
| 62 | state.set(came_from=REQUEST.get('came_from','login_success')) |
---|
| 63 | |
---|
| 64 | if came_from_prefs: |
---|
[1871] | 65 | context.plone_utils.addPortalMessage(_(u'User added.')) |
---|
[797] | 66 | state.set(status='prefs') |
---|
| 67 | |
---|
| 68 | from Products.CMFPlone.utils import transaction_note |
---|
| 69 | transaction_note('%s registered' % username) |
---|
| 70 | |
---|
| 71 | return state |
---|