Back to index

plone3  3.1.7
password_form.py
Go to the documentation of this file.
00001 ##parameters=change='', cancel=''
00002 ##
00003 from Products.CMFCore.utils import getUtilityByInterfaceName
00004 from Products.CMFCore.utils import getToolByName
00005 from Products.CMFDefault.utils import decode
00006 from Products.CMFDefault.utils import Message as _
00007 
00008 atool = getToolByName(script, 'portal_actions')
00009 mtool = getToolByName(script, 'portal_membership')
00010 ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool')
00011 utool = getToolByName(script, 'portal_url')
00012 member = mtool.getAuthenticatedMember()
00013 portal_url = utool()
00014 
00015 form = context.REQUEST.form
00016 if change and \
00017         context.change_password(**form) and \
00018         context.setRedirect(atool, 'user/preferences'):
00019     return
00020 elif cancel and \
00021         context.setRedirect(atool, 'user/preferences'):
00022     return
00023 
00024 
00025 options = {}
00026 
00027 is_first_login = (member.getProperty('last_login_time') == DateTime('1999/01/01'))
00028 options['is_first_login'] = is_first_login
00029 if is_first_login:
00030     options['title'] = _(u'Welcome!')
00031     options['portal_title'] = ptool.getProperty('title')
00032 else:
00033     options['title'] = _(u'Change your Password')
00034 options['member_id'] = member.getId()
00035 options['domains'] = ' '.join(member.getDomains())
00036 buttons = []
00037 target = '%s/password_form' % portal_url
00038 buttons.append( {'name': 'change', 'value': _(u'Change')} )
00039 if not is_first_login:
00040     buttons.append( {'name': 'cancel', 'value': _(u'Cancel')} )
00041 options['form'] = { 'action': target,
00042                     'listButtonInfos': tuple(buttons) }
00043 
00044 return context.password_form_template(**decode(options, script))