couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r1094082 - in /couchdb/trunk/share/www: _sidebar.html script/futon.js
Date Sat, 16 Apr 2011 22:49:34 GMT
Author: jan
Date: Sat Apr 16 22:49:33 2011
New Revision: 1094082

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

Closes COUCHDB-1015

Patch by Benjamin Young.

Modified:
    couchdb/trunk/share/www/_sidebar.html
    couchdb/trunk/share/www/script/futon.js

Modified: couchdb/trunk/share/www/_sidebar.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/_sidebar.html?rev=1094082&r1=1094081&r2=1094082&view=diff
==============================================================================
--- couchdb/trunk/share/www/_sidebar.html (original)
+++ couchdb/trunk/share/www/_sidebar.html Sat Apr 16 22:49:33 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/trunk/share/www/script/futon.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.js?rev=1094082&r1=1094081&r2=1094082&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.js (original)
+++ couchdb/trunk/share/www/script/futon.js Sat Apr 16 22:49:33 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();



Mime
View raw message