Commit de579ea9 authored by Vincent Pelletier's avatar Vincent Pelletier

Translate all messages.

Also, factorise & simplify code.
Also, follow coding style.
Also, follow naming conventions.
Also, avoid calling dict() for static key sets.
Also, add comments about bad code kept for backward compatibility.
Also, add comments about incorrect grammar - also kept for backward
compatibility.
parent fe62f181
...@@ -276,43 +276,51 @@ class PasswordTool(BaseTool): ...@@ -276,43 +276,51 @@ class PasswordTool(BaseTool):
""" """
Reset the password for a given login Reset the password for a given login
""" """
# check the key # BBB: password_confirm: unused argument
register_user_login, expiration_date = self._password_request_dict.get( def error(message):
password_key, (None, None)) # BBB: should "raise Redirect" instead of just returning, simplifying
# 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,
})
)
current_date = DateTime()
msg = None
if REQUEST is None: if REQUEST is None:
REQUEST = get_request() REQUEST = get_request()
site_url = self.getPortalObject().absolute_url()
if REQUEST and 'came_from' in REQUEST:
site_url = REQUEST.came_from
if self.getWebSiteValue(): if self.getWebSiteValue():
site_url = self.getWebSiteValue().absolute_url() site_url = self.getWebSiteValue().absolute_url()
if register_user_login is None: elif REQUEST and 'came_from' in REQUEST:
msg = "Key not known. Please ask reset password." site_url = REQUEST.came_from
elif user_login is not None and register_user_login != user_login: else:
msg = translateString("Bad login provided.") site_url = self.getPortalObject().absolute_url()
elif current_date > expiration_date: try:
msg = translateString("Date has expire.") register_user_login, expiration_date = self._password_request_dict[
if msg is not None: password_key]
if REQUEST is not None: except KeyError:
parameter = urlencode(dict(portal_status_message=msg)) # XXX: incorrect grammar and not descriptive enough
ret_url = '%s/login_form?%s' % (site_url, parameter) return error('Key not known. Please ask reset password.')
return REQUEST.RESPONSE.redirect( ret_url ) if user_login is not None and register_user_login != user_login:
else: # XXX: not descriptive enough
return msg return error("Bad login provided.")
if DateTime() > expiration_date:
# all is OK, change password and remove it from request dict # XXX: incorrect grammar
self._password_request_dict.pop(password_key) return error("Date has expire.")
persons = self.getPortalObject().acl_users.erp5_users.getUserByLogin(register_user_login) del self._password_request_dict[password_key]
persons = self.getPortalObject().acl_users.erp5_users.getUserByLogin(
register_user_login)
person = persons[0] person = persons[0]
person._forceSetPassword(password) person._forceSetPassword(password)
person.reindexObject() person.reindexObject()
if REQUEST is not None: if REQUEST is not None:
msg = translateString("Password changed.") return REQUEST.RESPONSE.redirect(
parameter = urlencode(dict(portal_status_message=msg)) site_url + '/login_form?' + urlencode({
ret_url = '%s/login_form?%s' % (site_url, parameter) 'portal_status_message': translateString("Password changed."),
return REQUEST.RESPONSE.redirect( ret_url ) })
)
InitializeClass(PasswordTool) 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