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', confirm='confirm', came_from_prefs=None |
---|
9 | ##title=Register a User |
---|
10 | ## |
---|
11 | from ZODB.POSException import ConflictError |
---|
12 | |
---|
13 | REQUEST=context.REQUEST |
---|
14 | |
---|
15 | portal_registration=context.portal_registration |
---|
16 | site_properties=context.portal_properties.site_properties |
---|
17 | |
---|
18 | username = REQUEST['username'] |
---|
19 | |
---|
20 | password=REQUEST.get('password') or portal_registration.generatePassword() |
---|
21 | |
---|
22 | # This is a temporary work-around for an issue with CMF not properly |
---|
23 | # reserving some existing ids (FSDV skin elements, for example). Until |
---|
24 | # this is fixed in the CMF we can at least fail nicely. See |
---|
25 | # http://plone.org/collector/2982 and http://plone.org/collector/3028 |
---|
26 | # for more info. (rohrer 2004-10-24) |
---|
27 | try: |
---|
28 | portal_registration.addMember(username, password, properties=REQUEST) |
---|
29 | except AttributeError: |
---|
30 | state.setError('username', 'The login name you selected is already in use or is not valid. Please choose another.') |
---|
31 | return state.set(status='failure', portal_status_message='Please correct the indicated errors.') |
---|
32 | |
---|
33 | if site_properties.validate_email or REQUEST.get('mail_me', 0): |
---|
34 | try: |
---|
35 | portal_registration.registeredNotify(username) |
---|
36 | except ConflictError: |
---|
37 | raise |
---|
38 | except Exception, err: |
---|
39 | |
---|
40 | #XXX registerdNotify calls into various levels. Lets catch all exceptions. |
---|
41 | # Should not fail. They cant CHANGE their password ;-) We should notify them. |
---|
42 | # |
---|
43 | # (MSL 12/28/03) We also need to delete the just made member and return to the join_form. |
---|
44 | |
---|
45 | state.setError('email', 'We were unable to send your password to your email address: '+str(err)) |
---|
46 | state.set(came_from='logged_in') |
---|
47 | context.acl_users.userFolderDelUsers([username,]) |
---|
48 | return state.set(status='failure', portal_status_message='Please enter a valid email address.') |
---|
49 | |
---|
50 | state.set(portal_status_message=REQUEST.get('portal_status_message', 'Registered.')) |
---|
51 | state.set(came_from=REQUEST.get('came_from','logged_in')) |
---|
52 | |
---|
53 | if came_from_prefs: |
---|
54 | state.set(status='prefs') |
---|
55 | |
---|
56 | from Products.CMFPlone import transaction_note |
---|
57 | transaction_note('%s registered' % username) |
---|
58 | |
---|
59 | return state |
---|