source: trunk/skins/lemill/plone_change_password.py @ 420

Revision 420, 1.9 KB checked in by jukka, 13 years ago (diff)

Fixed #491, spent 20min. Also fixed missing orange status bars when member-things are changed.

Line 
1## Script (Python) "plone_change_password"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##title=Action to change password
8##parameters=password, password_confirm, current, domains=None
9
10REQUEST=context.REQUEST
11
12mt=context.portal_membership
13member=mt.getAuthenticatedMember()
14home=mt.getHomeFolder(member.getId())
15
16if REQUEST.form.has_key('cancel'):
17    REQUEST.set('portal_status_message', 'Password change was canceled.')
18    return context.REQUEST.RESPONSE.redirect(home.absolute_url())
19
20
21if not mt.testCurrentPassword(current):
22    failMessage='Does not match current password.'
23    REQUEST.set('portal_status_message', 'Does not match current password.')
24    return context.password_form(context,
25                                 REQUEST,
26                                 error=failMessage)
27
28failMessage=context.portal_registration.testPasswordValidity(password, password_confirm)
29if failMessage:
30    REQUEST.set('portal_status_message', failMessage)
31    return context.password_form(context,
32                                 REQUEST,
33                                 error=failMessage)
34
35try:
36    mt.setPassword(password, domains)
37except AttributeError:
38    failMessage='While changing your password an AttributeError occurred.  This is usually caused by your user being defined outside the portal.'
39    REQUEST.set('portal_status_message', failMessage)
40    return context.password_form(context,
41                                 REQUEST,
42                                 error=failMessage)
43
44#mt.credentialsChanged(password) now in setPassword
45
46from Products.CMFPlone import transaction_note
47transaction_note('Changed password for %s' % (member.getUserName()))
48
49url='%s?portal_status_message=%s' % ( home.absolute_url()
50                                      , 'Password+changed.' )
51
52return context.REQUEST.RESPONSE.redirect(url)
Note: See TracBrowser for help on using the repository browser.