From: Benoît Pin Date: Tue, 28 Apr 2015 16:14:19 +0000 (+0200) Subject: Prise en charge de la redirection vers « came_from » lors de la ré-initialisation... X-Git-Url: https://svn.cri.ensmp.fr/git/Plinn.git/commitdiff_plain/ae75bab9028d6321710c42da338cef25c7afe576?ds=sidebyside;hp=f9f1aa2535d3fae8e35d803ba8c85f8891ec133c Prise en charge de la redirection vers « came_from » lors de la ré-initialisation de mot de passe. --- diff --git a/Products/Plinn/RegistrationTool.py b/Products/Plinn/RegistrationTool.py index 3e04db1..738d2ee 100644 --- a/Products/Plinn/RegistrationTool.py +++ b/Products/Plinn/RegistrationTool.py @@ -254,7 +254,7 @@ class RegistrationTool(BaseRegistrationTool) : return str(uuid4()) security.declarePublic('requestPasswordReset') - def requestPasswordReset(self, userid, initial=False): + def requestPasswordReset(self, userid, initial=False, came_from=''): """ add uuid / (userid, expiration) pair if ok: send an email to member. returns error message otherwise. """ @@ -274,7 +274,7 @@ class RegistrationTool(BaseRegistrationTool) : uuid = str(uuid4()) while self._passwordResetRequests.has_key(uuid) : uuid = str(uuid4()) - self._passwordResetRequests[uuid] = (userid, DateTime() + 1) + self._passwordResetRequests[uuid] = (userid, DateTime() + 1, came_from) utool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IURLTool') ptool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IPropertiesTool') # fuck : mailhost récupéré avec getUtilityByInterfaceName n'est pas correctement @@ -311,7 +311,7 @@ class RegistrationTool(BaseRegistrationTool) : def clearExpiredPasswordResetRequests(self): now = DateTime() for uuid, record in self._passwordResetRequests.items() : - userid, date = record + date = record[1] if date < now : del self._passwordResetRequests[uuid] @@ -322,7 +322,7 @@ class RegistrationTool(BaseRegistrationTool) : if not record : return None, _('Invalid reset password request.') - userid, expiration = record + userid, expiration, came_from = record now = DateTime() if expiration < now : self.clearExpiredPasswordResetRequests() @@ -335,7 +335,7 @@ class RegistrationTool(BaseRegistrationTool) : if member : member.setSecurityProfile(password=password) del self._passwordResetRequests[uuid] - return userid, _('Password successfully updated.') + return {'userid': userid, 'came_from' : came_from}, _('Password successfully updated.') else : return None, _('"${userid}" username not found.', mapping={'userid': userid}) else : diff --git a/Products/Plinn/skins/custom_generic/join_form.py b/Products/Plinn/skins/custom_generic/join_form.py index f7cdead..3badc16 100644 --- a/Products/Plinn/skins/custom_generic/join_form.py +++ b/Products/Plinn/skins/custom_generic/join_form.py @@ -37,11 +37,12 @@ if add : 'name' : name, 'email': member_email}) if validate_email : - rtool.requestPasswordReset(member_id, initial=True) + rtool.requestPasswordReset(member_id, initial=True, came_from=came_from) context.setStatus(True, _('Success!')) is_newmember = True is_anon = False except ValueError, errmsg: + raise context.setStatus(False, errmsg) options = {} diff --git a/Products/Plinn/skins/generic/password_reset_form.py b/Products/Plinn/skins/generic/password_reset_form.py index 9cb4b1d..7bd487a 100644 --- a/Products/Plinn/skins/generic/password_reset_form.py +++ b/Products/Plinn/skins/generic/password_reset_form.py @@ -10,18 +10,19 @@ uuid = traverse_subpath[0] passwordChanged = False if validate : - userid = context.reset_password_control(uuid=uuid, **form) - if userid : + infos = context.reset_password_control(uuid=uuid, **form) + if infos : passwordChanged = True options = {} options['uuid'] = uuid options['passwordChanged'] = passwordChanged if passwordChanged : - hidden_vars = ({'name' : '__ac_name', 'value' : userid}, + hidden_vars = ({'name' : '__ac_name', 'value' : infos['userid']}, {'name' : '__ac_password', 'value' : form['password']}, + {'name' : 'came_from', 'value' : infos['came_from']}, {'name' : 'noAjax', 'value' : '1'}) - target = utool() + target = atool.getActionInfo('user/logged_in')['url'] buttons = ({'name': 'login', 'value': _(' Login ')},) else : hidden_vars = []