couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject git commit: Fix change password dialog for admin users.
Date Sun, 30 Oct 2011 14:30:24 GMT
Updated Branches:
  refs/heads/master f4bdd95ed -> 84dea02aa


Fix change password dialog for admin users.

Fix change password for admin users that have a config entry as well
as a _users doc.

The password change flow is now:

 - if the current user has the _admin role set
   - if it has a corresponding config entry
     - update that entry
 - if the current user has a user doc
   - update that user doc


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/84dea02a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/84dea02a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/84dea02a

Branch: refs/heads/master
Commit: 84dea02aaaa8e3dc05bcf5a59474f4c332470afb
Parents: f4bdd95
Author: Jan Lehnardt <jan@apache.org>
Authored: Sun Oct 30 14:45:44 2011 +0100
Committer: Jan Lehnardt <jan@apache.org>
Committed: Sun Oct 30 15:30:21 2011 +0100

----------------------------------------------------------------------
 share/www/script/futon.js |   72 +++++++++++++++++++++++++---------------
 1 files changed, 45 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/84dea02a/share/www/script/futon.js
----------------------------------------------------------------------
diff --git a/share/www/script/futon.js b/share/www/script/futon.js
index fb73e3c..e179bbe 100644
--- a/share/www/script/futon.js
+++ b/share/www/script/futon.js
@@ -134,6 +134,30 @@ function $$(node) {
     };
 
     function changePassword () {
+      var updateUserDoc = function(resp, data) {
+        // regular users get their _users doc updated
+        $.couch.db(resp.info.authentication_db).openDoc("org.couchdb.user:"+resp.userCtx.name,
{
+          error: function () {
+            // ignore 404
+            location.reload();
+          },
+          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();
+                    }
+                  });
+                }
+              });
+            }
+        });
+      }
+
       $.showDialog("dialog/_change_password.html", {
         submit: function(data, callback) {
           if (validatePassword(data, callback)) {
@@ -145,36 +169,30 @@ function $$(node) {
             return false;
           }
           $.couch.session({success: function (resp) {
-            if (resp.userCtx.roles.indexOf("_admin") > -1) {
+            // admin users may have a config entry, change the password
+            // there first. Update their user doc later, if it exists
+            if (resp.userCtx.roles.indexOf("_admin") > -1) { // user is admin
+              // check whether we have a config entry
               $.couch.config({
-                success : function () {
-                  doLogin(resp.userCtx.name, data.password, function(errors) {
-                    if(!$.isEmptyObject(errors)) {
-                      callback(errors);
-                      return;
-                    } else {
-                      location.reload();
+                success : function (response) { // er do have a config entry
+                  $.couch.config({
+                    success : function () {
+                      window.setTimeout(function() {
+                        doLogin(resp.userCtx.name, data.password, function(errors) {
+                          if(!$.isEmptyObject(errors)) {
+                            callback(errors);
+                            return;
+                          } else {
+                            updateUserDoc(resp, data);
+                          }
+                        });
+                      } , 1000);
                     }
-                  });
+                  }, "admins", resp.userCtx.name, data.password);
                 }
-              }, "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();
-                              }
-                            });
-                          }
-                      });
-                  }
-              });
+              }, "admins", resp.userCtx.name);
+            } else { // non-admin users, update their user doc
+              updateUserDoc(resp, data);
             }
           }});
         }


Mime
View raw message