Back to index

plone3  3.1.7
plone_change_password.py
Go to the documentation of this file.
00001 ## Script (Python) "plone_change_password"
00002 ##bind container=container
00003 ##bind context=context
00004 ##bind namespace=
00005 ##bind script=script
00006 ##bind subpath=traverse_subpath
00007 ##title=Action to change password
00008 ##parameters=password, password_confirm, current, domains=None
00009 
00010 from Products.CMFPlone import PloneMessageFactory as _
00011 
00012 REQUEST=context.REQUEST
00013 if REQUEST.form.has_key('cancel'):
00014     context.plone_utils.addPortalMessage(_(u'Password change was canceled.'), 'warning')
00015     return context.plone_memberprefs_panel()
00016 
00017 mt=context.portal_membership
00018 
00019 if not mt.testCurrentPassword(current):
00020     failMessage=_(u'Does not match current password.')
00021     context.plone_utils.addPortalMessage(failMessage, 'error')
00022     return context.password_form(context,
00023                                  REQUEST,
00024                                  error=failMessage)
00025 
00026 failMessage=context.portal_registration.testPasswordValidity(password, password_confirm)
00027 if failMessage:
00028     context.plone_utils.addPortalMessage(failMessage, 'error')
00029     return context.password_form(context,
00030                                  REQUEST,
00031                                  error=failMessage)
00032 
00033 member=mt.getAuthenticatedMember()
00034 try:
00035     mt.setPassword(password, domains, REQUEST=context.REQUEST)
00036 except AttributeError:
00037     failMessage=_(u'While changing your password an AttributeError occurred. This is usually caused by your user being defined outside the portal.')
00038     context.plone_utils.addPortalMessage(failMessage, 'error')
00039     return context.password_form(context,
00040                                  REQUEST,
00041                                  error=failMessage)
00042 
00043 from Products.CMFPlone.utils import transaction_note
00044 transaction_note('Changed password for %s' % (member.getUserName()))
00045 
00046 context.plone_utils.addPortalMessage(_(u'Password changed.'))
00047 
00048 return context.REQUEST.RESPONSE.redirect('%s/plone_memberprefs_panel' % context.absolute_url())