Commit b7401807 authored by Vincent Pelletier's avatar Vincent Pelletier

PasswordTool: Redirect only when response is able to.

We now check if RESPONSE.redirect() exists, because TimerResponse does
not have redirect(). Currently TImerResponse is used only in
dummyGroupMethod (or any grouping method ?) but ideally it should be
used in any activity.
parent 34a9bc61
......@@ -43,6 +43,15 @@ from Products.ERP5Type.Globals import PersistentMapping
from BTrees.OOBTree import OOBTree
from urllib import urlencode
redirect_path = '/login_form'
def redirect(REQUEST, site_url, message):
if REQUEST is not None and getattr(REQUEST.RESPONSE, 'redirect', None) is not None:
parameter = urlencode({'portal_status_message': message})
ret_url = '%s%s?%s' % (site_url, redirect_path, parameter)
return REQUEST.RESPONSE.redirect( ret_url )
else:
return message
class PasswordTool(BaseTool):
"""
PasswordTool is used to allow a user to change its password
......@@ -150,12 +159,7 @@ class PasswordTool(BaseTool):
"User ${user} does not have an email address, please contact site "
"administrator directly", mapping={'user':user_login})
if msg:
if REQUEST is not None:
parameter = urlencode(dict(portal_status_message=msg))
ret_url = '%s/login_form?%s' % \
(site_url, parameter)
return REQUEST.RESPONSE.redirect( ret_url )
return msg
return redirect(REQUEST, site_url, msg)
key = self.getResetPasswordKey(user_login=user_login,
expiration_date=expiration_date)
......@@ -202,11 +206,8 @@ class PasswordTool(BaseTool):
store_as_event=store_as_event,
message_text_format=message_text_format,
event_keyword_argument_dict=event_keyword_argument_dict)
if REQUEST is not None:
msg = translateString("An email has been sent to you.")
parameter = urlencode(dict(portal_status_message=msg))
ret_url = '%s/login_form?%s' % (site_url, parameter)
return REQUEST.RESPONSE.redirect( ret_url )
return redirect(REQUEST, site_url,
translateString("An email has been sent to you."))
def _generateUUID(self, args=""):
"""
......@@ -274,13 +275,7 @@ class PasswordTool(BaseTool):
# calling code and making mistakes more difficult
# BBB: should probably not translate message when REQUEST is None
message = translateString(message)
if REQUEST is None:
return message
return REQUEST.RESPONSE.redirect(
site_url + '/login_form?' + urlencode({
'portal_status_message': message,
})
)
return redirect(REQUEST, site_url, message)
if REQUEST is None:
REQUEST = get_request()
......@@ -308,11 +303,7 @@ class PasswordTool(BaseTool):
person = persons[0]
person._forceSetPassword(password)
person.reindexObject()
if REQUEST is not None:
return REQUEST.RESPONSE.redirect(
site_url + '/login_form?' + urlencode({
'portal_status_message': translateString("Password changed."),
})
)
return redirect(REQUEST, site_url,
translateString("Password changed."))
InitializeClass(PasswordTool)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment