source: products/quintagroup.plonecaptchas/trunk/quintagroup/plonecaptchas/skins/captchas_join_form/register.cpy @ 1863

Last change on this file since 1863 was 1863, checked in by liebster, 14 years ago

Changed definition plone message factory for using i18ndude rebuild

File size: 2.9 KB
Line 
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
12from Products.CMFPlone import PloneMessageFactory as pmf
13from ZODB.POSException import ConflictError
14
15REQUEST = context.REQUEST
16
17portal = context.portal_url.getPortalObject()
18portal_registration = context.portal_registration
19
20username = REQUEST['username']
21
22password=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)
29try:
30    portal_registration.addMember(username, password, properties=REQUEST, REQUEST=context.REQUEST)
31except AttributeError:
32    state.setError('username', pmf(u'The login name you selected is already in use or is not valid. Please choose another.'))
33    context.plone_utils.addPortalMessage(pmf(u'Please correct the indicated errors.'), 'error')
34    return state.set(status='failure')
35
36if 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)
51            msg = pmf(u'status_fatal_password_mail',
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:
57            msg = pmf(u'status_nonfatal_password_mail',
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
62state.set(came_from=REQUEST.get('came_from','login_success'))
63
64if came_from_prefs:
65    context.plone_utils.addPortalMessage(pmf(u'User added.'))
66    state.set(status='prefs')
67
68from Products.CMFPlone.utils import transaction_note
69transaction_note('%s registered' % username)
70
71return state
Note: See TracBrowser for help on using the repository browser.