From 5f5f3baf2e48ef14a5272c3d1e4e9ac444d11e7c Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sat, 16 Apr 2011 22:49:55 +0000 Subject: Add "change password" feature to Futon. Closes COUCHDB-1015 Patch by Benjamin Young. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1094083 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/_sidebar.html | 13 ++++++----- share/www/script/futon.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) (limited to 'share') diff --git a/share/www/_sidebar.html b/share/www/_sidebar.html index 13727cbd..563a85c8 100644 --- a/share/www/_sidebar.html +++ b/share/www/_sidebar.html @@ -35,16 +35,15 @@ specific language governing permissions and limitations under the License. Signup or Login - Welcome ?! + Welcome ?!
+ + Setup more admins or +
+
+ Change password or Logout
- - Welcome ?! -
- Setup more admins or - Logout -
Welcome to Admin Party!
diff --git a/share/www/script/futon.js b/share/www/script/futon.js index c4647ed1..fb73e3c9 100644 --- a/share/www/script/futon.js +++ b/share/www/script/futon.js @@ -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(); -- cgit v1.2.3