You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2011/04/17 00:49:55 UTC

svn commit: r1094083 - in /couchdb/branches/1.1.x/share/www: _sidebar.html script/futon.js

Author: jan
Date: Sat Apr 16 22:49:55 2011
New Revision: 1094083

URL: http://svn.apache.org/viewvc?rev=1094083&view=rev
Log:
Add "change password" feature to Futon.

Closes COUCHDB-1015

Patch by Benjamin Young.

Modified:
    couchdb/branches/1.1.x/share/www/_sidebar.html
    couchdb/branches/1.1.x/share/www/script/futon.js

Modified: couchdb/branches/1.1.x/share/www/_sidebar.html
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/_sidebar.html?rev=1094083&r1=1094082&r2=1094083&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/_sidebar.html (original)
+++ couchdb/branches/1.1.x/share/www/_sidebar.html Sat Apr 16 22:49:55 2011
@@ -35,16 +35,15 @@ specific language governing permissions 
         <a href="#" class="signup">Signup</a> or <a href="#" class="login">Login</a>
       </span>
       <span class="loggedin">
-        Welcome <a class="name">?</a>! 
+        Welcome <a class="name">?</a>!
         <br/>
+        <span class="loggedinadmin">
+          <a href="#" class="createadmin">Setup more admins</a> or
+          <br/>
+        </span>
+        <a href="#" class="changepass">Change password</a> or
         <a href="#" class="logout">Logout</a>
       </span>
-      <span class="loggedinadmin">
-        Welcome <a class="name">?</a>! 
-        <br/>
-        <a href="#" class="createadmin">Setup more admins</a> or
-        <a href="#" class="logout">Logout</a> 
-      </span>
       <span class="adminparty">
         Welcome to Admin Party! 
         <br/>

Modified: couchdb/branches/1.1.x/share/www/script/futon.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/futon.js?rev=1094083&r1=1094082&r2=1094083&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/futon.js (original)
+++ couchdb/branches/1.1.x/share/www/script/futon.js Sat Apr 16 22:49:55 2011
@@ -68,6 +68,10 @@ function $$(node) {
         callback({name: "Please enter a name."});
         return false;
       };
+      return validatePassword(data, callback);
+    };
+
+    function validatePassword(data, callback) {
       if (!data.password || data.password.length == 0) {
         callback({password: "Please enter a password."});
         return false;
@@ -129,11 +133,61 @@ function $$(node) {
       return false;
     };
 
+    function changePassword () {
+      $.showDialog("dialog/_change_password.html", {
+        submit: function(data, callback) {
+          if (validatePassword(data, callback)) {
+            if (data.password != data.verify_password) {
+              callback({verify_password: "Passwords don't match."});
+              return false;
+            }
+          } else {
+            return false;
+          }
+          $.couch.session({success: function (resp) {
+            if (resp.userCtx.roles.indexOf("_admin") > -1) {
+              $.couch.config({
+                success : function () {
+                  doLogin(resp.userCtx.name, data.password, function(errors) {
+                    if(!$.isEmptyObject(errors)) {
+                      callback(errors);
+                      return;
+                    } else {
+                      location.reload();
+                    }
+                  });
+                }
+              }, "admins", resp.userCtx.name, data.password);
+            } else {
+              $.couch.db(resp.info.authentication_db).openDoc("org.couchdb.user:"+resp.userCtx.name, {
+                success: function (user) {
+                    $.couch.db(resp.info.authentication_db).saveDoc($.couch.prepareUserDoc(user, data.password), {
+                      success: function() {
+                          doLogin(user.name, data.password, function(errors) {
+                              if(!$.isEmptyObject(errors)) {
+                                callback(errors);
+                                return;
+                              } else {
+                                location.reload();
+                              }
+                            });
+                          }
+                      });
+                  }
+              });
+            }
+          }});
+        }
+      });
+      return false;
+    };
+
     this.setupSidebar = function() {
       $("#userCtx .login").click(login);
       $("#userCtx .logout").click(logout);
       $("#userCtx .signup").click(signup);
       $("#userCtx .createadmin").click(createAdmin);
+      $("#userCtx .changepass").click(changePassword);
     };
     
     this.sidebar = function() {
@@ -146,6 +200,7 @@ function $$(node) {
           if (userCtx.name) {
             $("#userCtx .name").text(userCtx.name).attr({href : $.couch.urlPrefix + "/_utils/document.html?"+encodeURIComponent(r.info.authentication_db)+"/org.couchdb.user%3A"+encodeURIComponent(userCtx.name)});
             if (userCtx.roles.indexOf("_admin") != -1) {
+              $("#userCtx .loggedin").show();
               $("#userCtx .loggedinadmin").show();
             } else {
               $("#userCtx .loggedin").show();