Author: channa
Date: Sun Mar  9 23:24:17 2008
New Revision: 14626

Log:

Adding profile option for current user to change password. WIP fix for 
MASHUP-655.

Modified:
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
   trunk/mashup/java/modules/www/ajax_profile.jsp
   trunk/mashup/java/modules/www/user.jsp

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
  (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
  Sun Mar  9 23:24:17 2008
@@ -636,6 +636,21 @@
     }
 
     /**
+     * Extracts the new and old password values from the string provided and 
calls user manager to
+     * change the user's password.
+     * @param storeAdmin User store admin instance.
+     * @param userName Name of user, who's password is to be changed.
+     * @param values String containing old and new password values.
+     * @throws UserStoreException If the update fails.
+     */
+    public static void changeUserPassword(UserStoreAdmin storeAdmin, String 
userName, String values)
+            throws UserStoreException {
+        // Extract the old and new passwords from the value string.
+        String[] passwords = values.split("&");
+        storeAdmin.updateUser(userName, passwords[1], passwords[0]);
+    }
+
+    /**
      * Gets the profile for a given user and returns if he ir she is the 
primary user.
      *
      * @param realm    Registry realm.

Modified: trunk/mashup/java/modules/www/ajax_profile.jsp
==============================================================================
--- trunk/mashup/java/modules/www/ajax_profile.jsp      (original)
+++ trunk/mashup/java/modules/www/ajax_profile.jsp      Sun Mar  9 23:24:17 2008
@@ -54,8 +54,9 @@
                     userStoreAdmin.setUserProperties(currentUser, properties);
                     success = true;
                 }
+            } else if (fieldParam.equals(MashupConstants.PASSWORD)) {
+                RegistryUtils.changeUserPassword(userStoreAdmin, currentUser, 
value);
             } else {
-
                 UserRealm realm = (UserRealm) 
request.getSession().getServletContext().
                         getAttribute(RegistryConstants.REGISTRY_REALM);
 

Modified: trunk/mashup/java/modules/www/user.jsp
==============================================================================
--- trunk/mashup/java/modules/www/user.jsp      (original)
+++ trunk/mashup/java/modules/www/user.jsp      Sun Mar  9 23:24:17 2008
@@ -159,6 +159,36 @@
                 }
             });
         }
+
+        function showControls(field) {
+            $(field + "_input").show();
+            $(field).hide();
+            $("passwordMessages_value").clear();
+        }
+
+        function updatePassword(field, fieldtype, user) {
+            var oldPassword = $("oldPassword_input_text").value;
+            var newPassword = $("newPassword_input_text").value;
+            var newPasswordConf = $("newPasswordConf_input_text").value;
+
+            if (newPassword != newPasswordConf) {
+                $("passwordMessages_value").update("New passwords do not 
match");
+            } else {
+                var changeDetails = oldPassword + "&" + newPassword;
+                new Ajax.Request("ajax_profile.jsp?name=" + user + "&field=" + 
fieldtype, {
+                    method: "post",
+                    contentType: "text/html",
+                    postBody: changeDetails,
+                    onFailure: function (transport) {
+                        alert("Trouble contacting WSO2 Mashup Server ajax 
service.  Please try again later.");
+                    },
+                    onSuccess: function (transport) {
+                        cancelEditable(field);
+                    }
+                });
+            }
+        }
+
     </script>
 
 </head>
@@ -275,6 +305,38 @@
                 </td>
             </tr>
             <% } %>
+            <% if (RegistryUtils.getCurrentUser(registry).equals(memberName)) 
{ %>
+            <tr>
+                <td class="profile_label">
+                    <nobr>Password:</nobr>
+                </td>
+                <td>
+                    <div class="profile_password">
+                            <span id="editPassword">
+                                <span class="edit-link">[<a href="#"
+                                                            
onclick="showControls('editPassword')">change</a>]</span>
+                            </span>
+                            <span id="editPassword_input" style="display:none">
+                                <table>
+                                    <tr><td class="profile_label">
+                                Old Password: </td><td><input type="password" 
id="oldPassword_input_text">
+                                     </td></tr>
+                                    <tr><td class="profile_label">
+                                New Password: </td><td><input type="password" 
id="newPassword_input_text">
+                                         </td></tr>
+                                    <tr><td class="profile_label">
+                                Confirmation: </td><td><input type="password" 
id="newPasswordConf_input_text">
+                                </td></tr></table>
+                                <span id="passwordMessages_value"></span>
+                                <span class="edit-link">[<a href="#"
+                                                            
onclick="cancelEditable('editPassword')">cancel</a>]</span>
+                                <span class="edit-link">[<a href="#"
+                                                            
onclick="updatePassword('editPassword', 'password', 
'<%=RegistryUtils.getCurrentUser(registry)%>')">update</a>]</span>
+                            </span>
+                    </div>
+                </td>
+            </tr>
+            <% } %>
         </table>
     </div>
 </td>

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to