diff options
Diffstat (limited to 'share/www/script')
-rw-r--r-- | share/www/script/futon.js | 55 |
1 files changed, 55 insertions, 0 deletions
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(); |