couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [12/50] [abbrv] fauxton commit: updated refs/heads/import-master to b32c617
Date Tue, 01 Apr 2014 09:14:28 GMT
Fauxton: dry up promise error callbacks
Fauxton: Fix error if anon. user tries to create Admins

Fixes #COUCHDB-2170


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

Branch: refs/heads/import-master
Commit: 9993b1cc6fe47fe0ef7171a206d13fcce257cd04
Parents: 851b618
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Thu Mar 6 11:37:17 2014 -0500
Committer: suelockwood <deathbear@apache.org>
Committed: Thu Mar 6 11:40:30 2014 -0500

----------------------------------------------------------------------
 app/addons/auth/resources.js | 44 +++++++++++++--------------------------
 1 file changed, 15 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/9993b1cc/app/addons/auth/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/resources.js b/app/addons/auth/resources.js
index 2e359c9..71744e3 100644
--- a/app/addons/auth/resources.js
+++ b/app/addons/auth/resources.js
@@ -20,6 +20,18 @@ function (app, FauxtonAPI, CouchdbSession) {
 
   var Auth = new FauxtonAPI.addon();
 
+  var promiseErrorHandler = function (xhr, type, msg) {
+    msg = xhr;
+    if (arguments.length === 3) {
+      msg = xhr.responseJSON.reason;
+    }
+
+    FauxtonAPI.addNotification({
+      msg: msg,
+      type: 'error'
+    });
+  };
+
   var Admin = Backbone.Model.extend({
 
     url: function () {
@@ -58,7 +70,6 @@ function (app, FauxtonAPI, CouchdbSession) {
       this.messages = _.extend({},  {
           missingCredentials: 'Username or password cannot be blank.',
           passwordsNotMatch:  'Passwords do not match.',
-          incorrectCredentials: 'Incorrect username or password.',
           loggedIn: 'You have been logged in.',
           adminCreated: 'CouchDB admin created',
           changePassword: 'Your password has been updated.'
@@ -234,12 +245,7 @@ function (app, FauxtonAPI, CouchdbSession) {
         }
       });
 
-      promise.fail(function (rsp) {
-        FauxtonAPI.addNotification({
-          msg: 'Could not create admin. Reason' + rsp + '.',
-          type: 'error'
-        });
-      });
+      promise.fail(promiseErrorHandler);
     }
 
   });
@@ -264,18 +270,7 @@ function (app, FauxtonAPI, CouchdbSession) {
         FauxtonAPI.navigate('/');
       });
 
-      promise.fail(function (xhr, type, msg) {
-        if (arguments.length === 3) {
-          msg = FauxtonAPI.session.messages.incorrectCredentials;
-        } else {
-          msg = xhr;
-        }
-
-        FauxtonAPI.addNotification({
-          msg: msg,
-          type: 'error'
-        });
-      });
+      promise.fail(promiseErrorHandler);
     }
 
   });
@@ -302,16 +297,7 @@ function (app, FauxtonAPI, CouchdbSession) {
         that.$('#password-confirm').val('');
       });
 
-      promise.fail(function (xhr, error, msg) {
-        if (arguments.length < 3) {
-          msg = xhr;
-        }
-
-        FauxtonAPI.addNotification({
-          msg: xhr,
-          type: 'error'
-        });
-      });
+      promise.fail(promiseErrorHandler);
     }
   });
 


Mime
View raw message