diff options
-rw-r--r-- | share/www/_sidebar.html | 13 | ||||
-rw-r--r-- | share/www/script/futon.js | 55 |
2 files changed, 61 insertions, 7 deletions
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. <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/> 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(); |