Affichage d'un bouton de connexion, juste après la réinitialisation du mot de passe.
authorBenoît Pin <benoit.pin@gmail.com>
Fri, 2 Aug 2013 06:31:31 +0000 (08:31 +0200)
committerBenoît Pin <benoit.pin@gmail.com>
Fri, 2 Aug 2013 06:31:31 +0000 (08:31 +0200)
RegistrationTool.py
skins/control/reset_password_control.py
skins/generic/password_reset_form.py
skins/generic/password_reset_template.pt

index 72a7329..1417f30 100644 (file)
@@ -244,13 +244,13 @@ class RegistrationTool(BaseRegistrationTool) :
     def resetPassword(self, uuid, password, confirm) :
         record = self._passwordResetRequests.get(uuid)
         if not record :
-            return _('Invalid reset password request.')
+            return None, _('Invalid reset password request.')
         
         userid, expiration = record
         now = DateTime()
         if expiration < now :
             self.clearExpiredPasswordResetRequests()
-            return _('Your reset password request has expired. You can ask a new one.')
+            return None, _('Your reset password request has expired. You can ask a new one.')
         
         msg = self.testPasswordValidity(password, confirm=confirm)
         if not msg : # None if everything ok. Err message otherwise.
@@ -259,9 +259,9 @@ class RegistrationTool(BaseRegistrationTool) :
             if member :
                 member.setSecurityProfile(password=password)
                 del self._passwordResetRequests[uuid]
-                return _('Password successfully resetted.')
+                return  userid, _('Password successfully reset.')
             else :
-                return _('"%s" username not found.') % userid
+                return None, _('"%s" username not found.') % userid
             
         
 InitializeClass(RegistrationTool)
\ No newline at end of file
index f903e24..8cdcdb1 100644 (file)
@@ -2,8 +2,8 @@
 from Products.CMFCore.utils import getUtilityByInterfaceName
 rtool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IRegistrationTool')
 
-msg = rtool.resetPassword(uuid, password, confirm)
+userid, msg  = rtool.resetPassword(uuid, password, confirm)
 if msg :
-    return context.setStatus(False, msg)
-else :
-    return True
\ No newline at end of file
+    context.setStatus(False, msg)
+
+return userid
\ No newline at end of file
index b783b63..6dfb557 100644 (file)
@@ -1,19 +1,37 @@
 ##parameters=validate=''
 from Products.CMFCore.utils import getUtilityByInterfaceName
+from Products.Plinn.utils import Message as _
 utool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IURLTool')
 atool = getUtilityByInterfaceName('Products.CMFCore.interfaces.IActionsTool')
 
 form = context.REQUEST.form
 uuid = traverse_subpath[0]
 
+passwordChanged = False
+
 if validate and \
-    context.validatePassword(**form) and \
-    context.reset_password_control(uuid=uuid, **form) and \
-    context.setRedirect(atool, 'user/join', ajax=form.get('ajax')) :
-    return
+    context.validatePassword(**form) :
+    userid = context.reset_password_control(uuid=uuid, **form)
+    if userid :
+        passwordChanged = True
 
 options = {}
 options['uuid'] = uuid
-options['action'] = '%s/password_reset_form/%s' % (utool(), uuid)
+options['passwordChanged'] = passwordChanged
+if passwordChanged :
+    hidden_vars = ({'name' : '__ac_name',       'value' : userid},
+                   {'name' : '__ac_password',   'value' : form['password']},
+                   {'name' : 'noAjax',          'value' : '1'})
+    target = utool()
+    buttons = ({'name': 'login', 'value': _('Login')},)
+else :
+    hidden_vars = []
+    target = '%s/password_reset_form/%s' % (utool(), uuid)
+    buttons = ({'name': 'validate', 'value': _('Validate')},)
+
+options['form'] = { 'action': target,
+                    'listButtonInfos': tuple(buttons),
+                    'listHiddenVarInfos': hidden_vars }
+
 
 return context.password_reset_template(**options)
\ No newline at end of file
index 30c46b4..fc32ee0 100644 (file)
@@ -8,38 +8,52 @@
     
   </head>
   <body i18n:domain="plinn">
-    <div metal:fill-slot="main_no_tabs" tal:omit-tag="">
-      <form tal:attributes="action options/action">
-        <h2 i18n:translate="">Password resetting</h2>
-        <table class="TwoColumnForm">
-          <tr>
-            <td colspan="2">
-              <dl class="FieldHelp">
-                <dd i18n:translate="">
-                  Please enter a new password and clic on "Validate" button.
-                </dd>
-              </dl>
-            </td>
-          </tr>
-          <tr>
-            <th i18n:translate="">Password</th>
-            <td>
-              <input type="password" name="password"/>
-            </td>
-          </tr>
-          <tr>
-            <th i18n:translate="">Confirm</th>
-            <td>
-              <input type="password" name="confirm"/>
-            </td>
-          </tr>
-          <tr>
-            <td><br/></td>
-            <td>
-              <input type="submit" name="validate" value="Validate" i18n:attributes="value"/>
-            </td>
-          </tr>
-        </table>
+    <div metal:fill-slot="main_no_tabs"
+         tal:define="form options/form"
+         id="Desktop">
+      <form tal:attributes="action form/action">
+        <div tal:condition="not: options/passwordChanged" tal:omit-tag="">
+          <h2 i18n:translate="">Password resetting</h2>
+          <table class="TwoColumnForm">
+            <tr>
+              <td colspan="2">
+                <dl class="FieldHelp">
+                  <dd i18n:translate="">
+                    Please enter a new password and clic on "Validate" button.
+                  </dd>
+                </dl>
+              </td>
+            </tr>
+            <tr>
+              <th i18n:translate="">Password</th>
+              <td>
+                <input type="password" name="password"/>
+              </td>
+            </tr>
+            <tr>
+              <th i18n:translate="">Confirm</th>
+              <td>
+                <input type="password" name="confirm"/>
+              </td>
+            </tr>
+            <tr>
+              <td><br/></td>
+              <td>
+                <metal:macro metal:use-macro="context/form_widgets/macros/hidden_vars"/>
+                <metal:macro metal:use-macro="context/form_widgets/macros/buttons"/>
+              </td>
+            </tr>
+          </table>
+        </div>
+        <div tal:condition="options/passwordChanged" tal:omit-tag="">
+          <h2 i18n:translate="">Password changed</h2>
+          <p i18n:translate="">
+            Your password has been successfully reset. You can log in
+            immediately by clicking the "Login" button
+          </p>
+          <metal:macro metal:use-macro="context/form_widgets/macros/hidden_vars"/>
+          <metal:macro metal:use-macro="context/form_widgets/macros/buttons"/>
+        </div>
       </form>
     </div>
   </body>