You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2016/05/31 07:58:54 UTC
[26/27] fauxton commit: updated refs/heads/master to 0ca35da
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/activetasks/tests/activetasks.storesSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/activetasks/tests/activetasks.storesSpec.js b/app/addons/activetasks/tests/activetasks.storesSpec.js
index 82f47d0..d408ef2 100644
--- a/app/addons/activetasks/tests/activetasks.storesSpec.js
+++ b/app/addons/activetasks/tests/activetasks.storesSpec.js
@@ -9,183 +9,180 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../../core/api',
- '../resources',
- '../stores',
- './fakeActiveTaskResponse',
- 'react',
- '../../../../test/mocha/testUtils',
- 'react-addons-test-utils',
- 'sinon'
-], function (FauxtonAPI, ActiveTasks, Stores, fakedResponse, React, utils, TestUtils, sinon) {
- var assert = utils.assert;
- var restore = utils.restore;
-
- var activeTasksStore = Stores.activeTasksStore;
- var activeTasksCollection = new ActiveTasks.AllTasks();
- activeTasksCollection.parse(fakedResponse);
-
- describe('Active Tasks -- Stores', function () {
- var spy, clock;
+import FauxtonAPI from "../../../core/api";
+import ActiveTasks from "../resources";
+import Stores from "../stores";
+import fakedResponse from "./fakeActiveTaskResponse";
+import React from "react";
+import utils from "../../../../test/mocha/testUtils";
+import TestUtils from "react-addons-test-utils";
+import sinon from "sinon";
+var assert = utils.assert;
+var restore = utils.restore;
+
+var activeTasksStore = Stores.activeTasksStore;
+var activeTasksCollection = new ActiveTasks.AllTasks();
+activeTasksCollection.parse(fakedResponse);
+
+describe('Active Tasks -- Stores', function () {
+ var spy, clock;
+
+ beforeEach(function () {
+ activeTasksStore.initAfterFetching(activeTasksCollection.table, activeTasksCollection);
+ clock = sinon.useFakeTimers();
+ });
+
+ afterEach(function () {
+ restore(spy);
+ clock.restore();
+ });
+
+ describe('Active Task Stores - Polling', function () {
+ var pollingWidgetDiv, pollingWidget;
beforeEach(function () {
activeTasksStore.initAfterFetching(activeTasksCollection.table, activeTasksCollection);
- clock = sinon.useFakeTimers();
});
afterEach(function () {
- restore(spy);
- clock.restore();
+ restore(activeTasksStore.getPollingInterval);
+ restore(window.clearInterval);
});
- describe('Active Task Stores - Polling', function () {
- var pollingWidgetDiv, pollingWidget;
-
- beforeEach(function () {
- activeTasksStore.initAfterFetching(activeTasksCollection.table, activeTasksCollection);
- });
-
- afterEach(function () {
- restore(activeTasksStore.getPollingInterval);
- restore(window.clearInterval);
- });
-
- it('should poll at the min time', function () {
- spy = sinon.spy(activeTasksStore, 'getPollingInterval');
- var minTime = 1;
- activeTasksStore.setPollingInterval(minTime);
- activeTasksStore.setPolling();
- assert.ok(spy.calledOnce);
+ it('should poll at the min time', function () {
+ spy = sinon.spy(activeTasksStore, 'getPollingInterval');
+ var minTime = 1;
+ activeTasksStore.setPollingInterval(minTime);
+ activeTasksStore.setPolling();
+ assert.ok(spy.calledOnce);
- setInterval(spy, minTime * 1000);
- clock.tick(minTime * 1000);
- assert.ok(spy.calledTwice);
+ setInterval(spy, minTime * 1000);
+ clock.tick(minTime * 1000);
+ assert.ok(spy.calledTwice);
- clock.tick(minTime * 1000);
- assert.ok(spy.calledThrice);
- });
+ clock.tick(minTime * 1000);
+ assert.ok(spy.calledThrice);
+ });
- it('should poll at the max time', function () {
- spy = sinon.spy(activeTasksStore, 'getPollingInterval');
+ it('should poll at the max time', function () {
+ spy = sinon.spy(activeTasksStore, 'getPollingInterval');
- var maxTime = 30;
- activeTasksStore.setPollingInterval(maxTime);
- activeTasksStore.setPolling();
- assert.ok(spy.calledOnce);
+ var maxTime = 30;
+ activeTasksStore.setPollingInterval(maxTime);
+ activeTasksStore.setPolling();
+ assert.ok(spy.calledOnce);
- setInterval(spy, maxTime * 1000);
- clock.tick(maxTime * 1000);
- assert.ok(spy.calledTwice);
+ setInterval(spy, maxTime * 1000);
+ clock.tick(maxTime * 1000);
+ assert.ok(spy.calledTwice);
- clock.tick(maxTime * 1000);
- assert.ok(spy.calledThrice);
- });
+ clock.tick(maxTime * 1000);
+ assert.ok(spy.calledThrice);
+ });
- it('should poll at a mid time', function () {
- spy = sinon.spy(activeTasksStore, 'getPollingInterval');
+ it('should poll at a mid time', function () {
+ spy = sinon.spy(activeTasksStore, 'getPollingInterval');
- var midtime = 15;
- activeTasksStore.setPollingInterval(midtime);
- activeTasksStore.setPolling();
- assert.ok(spy.calledOnce);
+ var midtime = 15;
+ activeTasksStore.setPollingInterval(midtime);
+ activeTasksStore.setPolling();
+ assert.ok(spy.calledOnce);
- setInterval(spy, midtime * 1000);
- clock.tick(midtime * 1000);
- assert.ok(spy.calledTwice);
+ setInterval(spy, midtime * 1000);
+ clock.tick(midtime * 1000);
+ assert.ok(spy.calledTwice);
- clock.tick(midtime * 1000);
- assert.ok(spy.calledThrice);
- });
+ clock.tick(midtime * 1000);
+ assert.ok(spy.calledThrice);
+ });
- it('should clear interval each time', function () {
- var spy = sinon.spy(window, 'clearInterval');
- activeTasksStore.setPolling();
- assert.ok(spy.calledOnce);
- });
+ it('should clear interval each time', function () {
+ var spy = sinon.spy(window, 'clearInterval');
+ activeTasksStore.setPolling();
+ assert.ok(spy.calledOnce);
+ });
- it('should set the isLoading variable so that the loading lines show up', function () {
- spy = sinon.spy(activeTasksStore, 'setIsLoading');
- var date = new Date();
+ it('should set the isLoading variable so that the loading lines show up', function () {
+ spy = sinon.spy(activeTasksStore, 'setIsLoading');
+ var date = new Date();
- activeTasksCollection.pollingFetch();
- assert.ok(spy.withArgs(true, date).calledOnce);
+ activeTasksCollection.pollingFetch();
+ assert.ok(spy.withArgs(true, date).calledOnce);
- activeTasksCollection.parse(fakedResponse);
- assert.ok(spy.withArgs(false, date).calledOnce);
+ activeTasksCollection.parse(fakedResponse);
+ assert.ok(spy.withArgs(false, date).calledOnce);
- restore(activeTasksStore.setIsLoading);
- });
+ restore(activeTasksStore.setIsLoading);
});
+ });
- describe('Active Task Stores - Filter Tab Tray', function () {
- var fakeFilteredTable, storeFilteredtable;
- function sort (a, b, sortBy) { //sorts array by objects with key 'sortBy', with default started_on
- if (_.isUndefined(sortBy)) {
- sortBy = 'started-on';
- }
- return b[sortBy] - a[sortBy];
+ describe('Active Task Stores - Filter Tab Tray', function () {
+ var fakeFilteredTable, storeFilteredtable;
+ function sort (a, b, sortBy) { //sorts array by objects with key 'sortBy', with default started_on
+ if (_.isUndefined(sortBy)) {
+ sortBy = 'started-on';
}
+ return b[sortBy] - a[sortBy];
+ }
- afterEach(function () {
- fakeFilteredTable = [];
- });
+ afterEach(function () {
+ fakeFilteredTable = [];
+ });
- it('should filter the table correctly, by radio -- All Tasks', function () {
- activeTasksStore.setSelectedRadio('all_tasks');
- //parse table and check that it only contains objects any type
- var table = activeTasksStore.getFilteredTable(activeTasksStore._collection);
- assert.ok(activeTasksStore._collection.length, table.length);
- });
+ it('should filter the table correctly, by radio -- All Tasks', function () {
+ activeTasksStore.setSelectedRadio('all_tasks');
+ //parse table and check that it only contains objects any type
+ var table = activeTasksStore.getFilteredTable(activeTasksStore._collection);
+ assert.ok(activeTasksStore._collection.length, table.length);
+ });
- it('should filter the table correctly, by radio', function () {
- activeTasksStore.setSelectedRadio('replication');
- var storeFilteredtable = activeTasksStore.getFilteredTable(activeTasksStore._collection);
+ it('should filter the table correctly, by radio', function () {
+ activeTasksStore.setSelectedRadio('replication');
+ var storeFilteredtable = activeTasksStore.getFilteredTable(activeTasksStore._collection);
- //parse table and check that it only contains objects with type: Replication
- _.each(storeFilteredtable, function (activeTask) {
- assert.ok(activeTasksStore.passesRadioFilter(activeTask));
- assert.deepEqual(activeTask.type, activeTasksStore.getSelectedRadio());
- });
+ //parse table and check that it only contains objects with type: Replication
+ _.each(storeFilteredtable, function (activeTask) {
+ assert.ok(activeTasksStore.passesRadioFilter(activeTask));
+ assert.deepEqual(activeTask.type, activeTasksStore.getSelectedRadio());
});
+ });
- it('should search the table correctly', function () {
- activeTasksStore.setSelectedRadio('all_tasks');
- var searchTerm = 'base';
- activeTasksStore.setSearchTerm(searchTerm);
- var storeGeneratedTable = activeTasksStore.getFilteredTable(activeTasksStore._collection);
- var regEx = new RegExp(searchTerm);
+ it('should search the table correctly', function () {
+ activeTasksStore.setSelectedRadio('all_tasks');
+ var searchTerm = 'base';
+ activeTasksStore.setSearchTerm(searchTerm);
+ var storeGeneratedTable = activeTasksStore.getFilteredTable(activeTasksStore._collection);
+ var regEx = new RegExp(searchTerm);
- fakeFilteredTable = [
- { user: 'information'},
- { user: 'ooo'}
- ];
+ fakeFilteredTable = [
+ { user: 'information'},
+ { user: 'ooo'}
+ ];
- assert.equal(fakeFilteredTable[0].user, storeGeneratedTable[0].user);
- assert.equal(fakeFilteredTable[1].user, storeGeneratedTable[1].user);
- });
+ assert.equal(fakeFilteredTable[0].user, storeGeneratedTable[0].user);
+ assert.equal(fakeFilteredTable[1].user, storeGeneratedTable[1].user);
});
+ });
- describe('Active Task Stores - Table Header Sort - Select Ascending/Descending', function () {
+ describe('Active Task Stores - Table Header Sort - Select Ascending/Descending', function () {
- it('should set header as ascending, on default', function () {
- activeTasksStore.setSelectedRadio('all-tasks');
- activeTasksStore._headerIsAscending = true;
- assert.ok(activeTasksStore.getHeaderIsAscending());
- });
+ it('should set header as ascending, on default', function () {
+ activeTasksStore.setSelectedRadio('all-tasks');
+ activeTasksStore._headerIsAscending = true;
+ assert.ok(activeTasksStore.getHeaderIsAscending());
+ });
- it('should set header as descending, if same header is selected again', function () {
- activeTasksStore._prevSortbyHeader = 'sameHeader';
- activeTasksStore._sortByHeader = 'sameHeader';
- activeTasksStore.toggleHeaderIsAscending();
- assert.notOk(activeTasksStore.getHeaderIsAscending());
- });
+ it('should set header as descending, if same header is selected again', function () {
+ activeTasksStore._prevSortbyHeader = 'sameHeader';
+ activeTasksStore._sortByHeader = 'sameHeader';
+ activeTasksStore.toggleHeaderIsAscending();
+ assert.notOk(activeTasksStore.getHeaderIsAscending());
+ });
- it('should set header as ascending, if different header is selected', function () {
- activeTasksStore._sortByHeader = 'differentHeader';
- activeTasksStore.toggleHeaderIsAscending();
- assert.ok(activeTasksStore.getHeaderIsAscending());
- });
+ it('should set header as ascending, if different header is selected', function () {
+ activeTasksStore._sortByHeader = 'differentHeader';
+ activeTasksStore.toggleHeaderIsAscending();
+ assert.ok(activeTasksStore.getHeaderIsAscending());
});
});
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/activetasks/tests/fakeActiveTaskResponse.js
----------------------------------------------------------------------
diff --git a/app/addons/activetasks/tests/fakeActiveTaskResponse.js b/app/addons/activetasks/tests/fakeActiveTaskResponse.js
index 687e566..823b7f2 100644
--- a/app/addons/activetasks/tests/fakeActiveTaskResponse.js
+++ b/app/addons/activetasks/tests/fakeActiveTaskResponse.js
@@ -9,113 +9,111 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
-define([], function () {
- var fakeData = [
- {
- "user": "okra",
- "updated_on": 10,
- "type": "replication",
- "target": "https://okra.fake.com/okra_rep/",
- "doc_write_failures": 0,
- "doc_id": "rep_1",
- "continuous": true,
- "checkpointed_source_seq": "3-g1AAAAEkeJyFzkEOgjAQBdAJkHgOPUBDQS1dyVVmaE0l0CaIa72Z3qyOwahscPMn-Zm8_A4AMpca2BhqwmBrQzIXfQj-7E7eiqYLF4N-FN6OHf8mCHSIMbYuwbTnYiUllUbJl7H-GNUSQTUnXd8KTEqR467Qc0UtKT7jhBsfhu5fCa3SFR3nUvlfekzS76a9Vmi37RPEPVpb",
- "checkpoint_interval": 5000,
- "changes_pending": null,
- "pid": "<0.10487.5819>",
- "node": "fake1@fake.net",
- "docs_read": 0,
- "docs_written": 0,
- "missing_revisions_found": 0,
- "replication_id": "07d9a41f181ce11b93ba1855ca7+continuous+create_target",
- "revisions_checked": 0,
- "source": "https://okra.fake.com/okra/",
- "source_seq": 0,
- "started_on": 9
- },
- {
- "user": "ooo",
- "updated_on": 8,
- "type": "indexer",
- "node": "fake2@fake2.net",
- "pid": "<0.10541.4469>",
- "changes_done": 145,
- "database": "shards/00000000-3fffffff/ooo/fakedatabase.1234567890abc",
- "design_document": "_design/superpurple",
- "progress": 0,
- "started_on": 7,
- "total_changes": 22942
- },
- {
- "updated_on": 6,
- "node": "fake3@fake3.net",
- "pid": "<0.1152.4474>",
- "changes_done": 144001,
- "database": "shards/00000000-3fffffff/global_changes.1398718618",
- "progress": 66,
- "started_on": 5,
- "total_changes": 218052,
- "type": "database_compaction"
- },
- {
- "user": "information",
- "updated_on": 4,
- "type": "replication",
- "target": "https://information.com/somedatabase/",
- "doc_write_failures": 0,
- "doc_id": "c0ffb663f75cd940aadb4a4eaa",
- "continuous": true,
- "checkpointed_source_seq": 58717,
- "checkpoint_interval": 3600000,
- "changes_pending": 0,
- "pid": "<0.11612.3684>",
- "node": "fake.fake.com",
- "docs_read": 108,
- "docs_written": 108,
- "missing_revisions_found": 108,
- "replication_id": "a546c13951c6bd4f2d187d388+continuous",
- "revisions_checked": 1024,
- "source": "http://software:*****@123.123.123:5984/somedatabase/",
- "source_seq": 58717,
- "started_on": 3
- },
- {
- "user": "abc",
- "updated_on": 2,
- "type": "replication",
- "target": "https://fake.com/db_abc/",
- "doc_write_failures": 0,
- "doc_id": "replication_2014",
- "continuous": true,
- "checkpointed_source_seq": "2-g1AAAAEXeJzLYWBgYMlgTyrNSS3QS87JL01JzCvRy0styQGqY0pkSLL___9_VgZTImMuUIA9JSUx1cTIAE2_IS79SQ5AMqkexQiLNAPzNAsjYp2QxwIkGRqAFNCU_SBjGMDGGFokp6WZJ6IZY4TfmAMQY_4jjDE2SDE3TzHJAgBp5FSv",
- "checkpoint_interval": 5000,
- "changes_pending": 0,
- "pid": "<0.14029.1733>",
- "node": "node.node.node..net",
- "docs_read": 0,
- "docs_written": 0,
- "missing_revisions_found": 0,
- "replication_id": "33af566bab6a58aee04e+continuous",
- "revisions_checked": 7,
- "source": "https://fake.fake123.com/db_abc/",
- "source_seq": "2-g1AAAAEXeJzLYWBgYMlgS3QS87JL01JzCvRy0styQGqY0pkSLL___9_VgZTImMuUIA9JSUx1cTIAE2_IS79SQ5AMqkexQiLNAPzNAsjYp2QxwIkGRqAFNCU_SBjGMDGGFokp6WZJ6IZY4TfmAMQY_4jjDE2SDE3TzHJAgBp5FSv",
- "started_on": 1
- },
- {
- "view": 5,
- "user": "treeman",
- "updated_on": 1426614009,
- "type": "view_compaction",
- "total_changes": 1108953,
- "node": "treeman.net",
- "pid": "<0.19668.4045>",
- "changes_done": 430000,
- "database": "shards/c0000000-ffffffff/treecompany/fake.1234567890",
- "design_document": "_design/trunk",
- "phase": "view",
- "progress": 38,
- "started_on": 1426602505
- },
- ];
- return fakeData;
-});
+var fakeData = [
+ {
+ "user": "okra",
+ "updated_on": 10,
+ "type": "replication",
+ "target": "https://okra.fake.com/okra_rep/",
+ "doc_write_failures": 0,
+ "doc_id": "rep_1",
+ "continuous": true,
+ "checkpointed_source_seq": "3-g1AAAAEkeJyFzkEOgjAQBdAJkHgOPUBDQS1dyVVmaE0l0CaIa72Z3qyOwahscPMn-Zm8_A4AMpca2BhqwmBrQzIXfQj-7E7eiqYLF4N-FN6OHf8mCHSIMbYuwbTnYiUllUbJl7H-GNUSQTUnXd8KTEqR467Qc0UtKT7jhBsfhu5fCa3SFR3nUvlfekzS76a9Vmi37RPEPVpb",
+ "checkpoint_interval": 5000,
+ "changes_pending": null,
+ "pid": "<0.10487.5819>",
+ "node": "fake1@fake.net",
+ "docs_read": 0,
+ "docs_written": 0,
+ "missing_revisions_found": 0,
+ "replication_id": "07d9a41f181ce11b93ba1855ca7+continuous+create_target",
+ "revisions_checked": 0,
+ "source": "https://okra.fake.com/okra/",
+ "source_seq": 0,
+ "started_on": 9
+ },
+ {
+ "user": "ooo",
+ "updated_on": 8,
+ "type": "indexer",
+ "node": "fake2@fake2.net",
+ "pid": "<0.10541.4469>",
+ "changes_done": 145,
+ "database": "shards/00000000-3fffffff/ooo/fakedatabase.1234567890abc",
+ "design_document": "_design/superpurple",
+ "progress": 0,
+ "started_on": 7,
+ "total_changes": 22942
+ },
+ {
+ "updated_on": 6,
+ "node": "fake3@fake3.net",
+ "pid": "<0.1152.4474>",
+ "changes_done": 144001,
+ "database": "shards/00000000-3fffffff/global_changes.1398718618",
+ "progress": 66,
+ "started_on": 5,
+ "total_changes": 218052,
+ "type": "database_compaction"
+ },
+ {
+ "user": "information",
+ "updated_on": 4,
+ "type": "replication",
+ "target": "https://information.com/somedatabase/",
+ "doc_write_failures": 0,
+ "doc_id": "c0ffb663f75cd940aadb4a4eaa",
+ "continuous": true,
+ "checkpointed_source_seq": 58717,
+ "checkpoint_interval": 3600000,
+ "changes_pending": 0,
+ "pid": "<0.11612.3684>",
+ "node": "fake.fake.com",
+ "docs_read": 108,
+ "docs_written": 108,
+ "missing_revisions_found": 108,
+ "replication_id": "a546c13951c6bd4f2d187d388+continuous",
+ "revisions_checked": 1024,
+ "source": "http://software:*****@123.123.123:5984/somedatabase/",
+ "source_seq": 58717,
+ "started_on": 3
+ },
+ {
+ "user": "abc",
+ "updated_on": 2,
+ "type": "replication",
+ "target": "https://fake.com/db_abc/",
+ "doc_write_failures": 0,
+ "doc_id": "replication_2014",
+ "continuous": true,
+ "checkpointed_source_seq": "2-g1AAAAEXeJzLYWBgYMlgTyrNSS3QS87JL01JzCvRy0styQGqY0pkSLL___9_VgZTImMuUIA9JSUx1cTIAE2_IS79SQ5AMqkexQiLNAPzNAsjYp2QxwIkGRqAFNCU_SBjGMDGGFokp6WZJ6IZY4TfmAMQY_4jjDE2SDE3TzHJAgBp5FSv",
+ "checkpoint_interval": 5000,
+ "changes_pending": 0,
+ "pid": "<0.14029.1733>",
+ "node": "node.node.node..net",
+ "docs_read": 0,
+ "docs_written": 0,
+ "missing_revisions_found": 0,
+ "replication_id": "33af566bab6a58aee04e+continuous",
+ "revisions_checked": 7,
+ "source": "https://fake.fake123.com/db_abc/",
+ "source_seq": "2-g1AAAAEXeJzLYWBgYMlgS3QS87JL01JzCvRy0styQGqY0pkSLL___9_VgZTImMuUIA9JSUx1cTIAE2_IS79SQ5AMqkexQiLNAPzNAsjYp2QxwIkGRqAFNCU_SBjGMDGGFokp6WZJ6IZY4TfmAMQY_4jjDE2SDE3TzHJAgBp5FSv",
+ "started_on": 1
+ },
+ {
+ "view": 5,
+ "user": "treeman",
+ "updated_on": 1426614009,
+ "type": "view_compaction",
+ "total_changes": 1108953,
+ "node": "treeman.net",
+ "pid": "<0.19668.4045>",
+ "changes_done": 430000,
+ "database": "shards/c0000000-ffffffff/treecompany/fake.1234567890",
+ "design_document": "_design/trunk",
+ "phase": "view",
+ "progress": 38,
+ "started_on": 1426602505
+ },
+];
+export default fakeData;
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/actions.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/actions.js b/app/addons/auth/actions.js
index 088a220..104f057 100644
--- a/app/addons/auth/actions.js
+++ b/app/addons/auth/actions.js
@@ -9,112 +9,107 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../core/api',
- './actiontypes',
- '../cluster/cluster.stores'
-],
-function (FauxtonAPI, ActionTypes, ClusterStore) {
-
- var nodesStore = ClusterStore.nodesStore;
-
- var errorHandler = function (xhr, type, msg) {
- msg = xhr;
- if (arguments.length === 3) {
- msg = xhr.responseJSON.reason;
- }
-
- FauxtonAPI.addNotification({
- msg: msg,
- type: 'error'
+import FauxtonAPI from "../../core/api";
+import ActionTypes from "./actiontypes";
+import ClusterStore from "../cluster/cluster.stores";
+
+var nodesStore = ClusterStore.nodesStore;
+
+var errorHandler = function (xhr, type, msg) {
+ msg = xhr;
+ if (arguments.length === 3) {
+ msg = xhr.responseJSON.reason;
+ }
+
+ FauxtonAPI.addNotification({
+ msg: msg,
+ type: 'error'
+ });
+};
+
+
+export default {
+
+ login: function (username, password, urlBack) {
+ var promise = FauxtonAPI.session.login(username, password);
+
+ promise.then(function () {
+ FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.loggedIn });
+ if (urlBack) {
+ return FauxtonAPI.navigate(urlBack);
+ }
+ FauxtonAPI.navigate('/');
+ });
+ promise.fail(errorHandler);
+ },
+
+ changePassword: function (password, passwordConfirm) {
+ var nodes = nodesStore.getNodes();
+ var promise = FauxtonAPI.session.changePassword(password, passwordConfirm, nodes[0].node);
+
+ promise.done(function () {
+ FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.changePassword });
+ FauxtonAPI.dispatch({ type: ActionTypes.AUTH_CLEAR_CHANGE_PWD_FIELDS });
});
- };
+ promise.fail(errorHandler);
+ },
- return {
+ updateChangePasswordField: function (value) {
+ FauxtonAPI.dispatch({
+ type: ActionTypes.AUTH_UPDATE_CHANGE_PWD_FIELD,
+ value: value
+ });
+ },
- login: function (username, password, urlBack) {
- var promise = FauxtonAPI.session.login(username, password);
+ updateChangePasswordConfirmField: function (value) {
+ FauxtonAPI.dispatch({
+ type: ActionTypes.AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD,
+ value: value
+ });
+ },
- promise.then(function () {
- FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.loggedIn });
- if (urlBack) {
- return FauxtonAPI.navigate(urlBack);
- }
+ createAdmin: function (username, password, loginAfter) {
+ var nodes = nodesStore.getNodes();
+ var promise = FauxtonAPI.session.createAdmin(username, password, loginAfter, nodes[0].node);
+
+ promise.then(function () {
+ FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.adminCreated });
+ if (loginAfter) {
FauxtonAPI.navigate('/');
- });
- promise.fail(errorHandler);
- },
-
- changePassword: function (password, passwordConfirm) {
- var nodes = nodesStore.getNodes();
- var promise = FauxtonAPI.session.changePassword(password, passwordConfirm, nodes[0].node);
-
- promise.done(function () {
- FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.changePassword });
- FauxtonAPI.dispatch({ type: ActionTypes.AUTH_CLEAR_CHANGE_PWD_FIELDS });
- });
-
- promise.fail(errorHandler);
- },
-
- updateChangePasswordField: function (value) {
- FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_UPDATE_CHANGE_PWD_FIELD,
- value: value
- });
- },
-
- updateChangePasswordConfirmField: function (value) {
- FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD,
- value: value
- });
- },
-
- createAdmin: function (username, password, loginAfter) {
- var nodes = nodesStore.getNodes();
- var promise = FauxtonAPI.session.createAdmin(username, password, loginAfter, nodes[0].node);
-
- promise.then(function () {
- FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.adminCreated });
- if (loginAfter) {
- FauxtonAPI.navigate('/');
- } else {
- FauxtonAPI.dispatch({ type: ActionTypes.AUTH_CLEAR_CREATE_ADMIN_FIELDS });
- }
- });
-
- promise.fail(function (xhr, type, msg) {
- msg = xhr;
- if (arguments.length === 3) {
- msg = xhr.responseJSON.reason;
- }
- errorHandler(FauxtonAPI.session.messages.adminCreationFailedPrefix + ' ' + msg);
- });
- },
-
- updateCreateAdminUsername: function (value) {
- FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD,
- value: value
- });
- },
-
- updateCreateAdminPassword: function (value) {
- FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD,
- value: value
- });
- },
-
- selectPage: function (page) {
- FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_SELECT_PAGE,
- page: page
- });
- }
-
- };
-
-});
+ } else {
+ FauxtonAPI.dispatch({ type: ActionTypes.AUTH_CLEAR_CREATE_ADMIN_FIELDS });
+ }
+ });
+
+ promise.fail(function (xhr, type, msg) {
+ msg = xhr;
+ if (arguments.length === 3) {
+ msg = xhr.responseJSON.reason;
+ }
+ errorHandler(FauxtonAPI.session.messages.adminCreationFailedPrefix + ' ' + msg);
+ });
+ },
+
+ updateCreateAdminUsername: function (value) {
+ FauxtonAPI.dispatch({
+ type: ActionTypes.AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD,
+ value: value
+ });
+ },
+
+ updateCreateAdminPassword: function (value) {
+ FauxtonAPI.dispatch({
+ type: ActionTypes.AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD,
+ value: value
+ });
+ },
+
+ selectPage: function (page) {
+ FauxtonAPI.dispatch({
+ type: ActionTypes.AUTH_SELECT_PAGE,
+ page: page
+ });
+ }
+
+};
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/actiontypes.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/actiontypes.js b/app/addons/auth/actiontypes.js
index 29ce9bf..af3d02a 100644
--- a/app/addons/auth/actiontypes.js
+++ b/app/addons/auth/actiontypes.js
@@ -10,14 +10,12 @@
// License for the specific language governing permissions and limitations under
// the License.
-define([], function () {
- return {
- AUTH_CLEAR_CHANGE_PWD_FIELDS: 'AUTH_CLEAR_CHANGE_PWD_FIELDS',
- AUTH_UPDATE_CHANGE_PWD_FIELD: 'AUTH_UPDATE_CHANGE_PWD_FIELD',
- AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD: 'AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD',
- AUTH_CLEAR_CREATE_ADMIN_FIELDS: 'AUTH_CLEAR_CREATE_ADMIN_FIELDS',
- AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD: 'AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD',
- AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD: 'AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD',
- AUTH_SELECT_PAGE: 'AUTH_SELECT_PAGE'
- };
-});
+export default {
+ AUTH_CLEAR_CHANGE_PWD_FIELDS: 'AUTH_CLEAR_CHANGE_PWD_FIELDS',
+ AUTH_UPDATE_CHANGE_PWD_FIELD: 'AUTH_UPDATE_CHANGE_PWD_FIELD',
+ AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD: 'AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD',
+ AUTH_CLEAR_CREATE_ADMIN_FIELDS: 'AUTH_CLEAR_CREATE_ADMIN_FIELDS',
+ AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD: 'AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD',
+ AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD: 'AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD',
+ AUTH_SELECT_PAGE: 'AUTH_SELECT_PAGE'
+};
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/base.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/base.js b/app/addons/auth/base.js
index 07619c5..5956401 100644
--- a/app/addons/auth/base.js
+++ b/app/addons/auth/base.js
@@ -10,106 +10,101 @@
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../app',
- '../../core/api',
- './routes',
- './assets/less/auth.less'
-],
-
-function (app, FauxtonAPI, Auth) {
-
- Auth.session = new Auth.Session();
- FauxtonAPI.setSession(Auth.session);
- app.session = Auth.session;
-
- Auth.initialize = function () {
-
- FauxtonAPI.addHeaderLink({
- id: 'auth',
- title: 'Login',
- href: '#login',
- icon: 'fonticon-user',
- bottomNav: true
- });
-
- Auth.session.on('change', function () {
- var session = Auth.session;
- var link = {};
-
- if (session.isAdminParty()) {
- link = {
- id: 'auth',
- title: 'Admin Party!',
- href: '#createAdmin',
- icon: 'fonticon-user',
- bottomNav: true
- };
- } else if (session.isLoggedIn()) {
- link = {
- id: 'auth',
- title: session.user().name,
- href: '#changePassword',
- icon: 'fonticon-user',
- bottomNav: true
- };
-
- // ensure the footer link is removed before adding it
- FauxtonAPI.removeHeaderLink({ id: 'logout', footerNav: true });
- FauxtonAPI.addHeaderLink({
- id: 'logout',
- footerNav: true,
- href: '#logout',
- title: 'Logout',
- icon: '',
- className: 'logout'
- });
- } else {
- link = {
- id: 'auth',
- title: 'Login',
- href: '#login',
- icon: 'fonticon-user',
- bottomNav: true
- };
- FauxtonAPI.removeHeaderLink({ id: 'logout', footerNav: true });
- }
- FauxtonAPI.updateHeaderLink(link);
- });
-
- Auth.session.fetchUser().then(function () {
- Auth.session.trigger('change');
- });
-
- var auth = function (session, roles) {
- var deferred = $.Deferred();
-
- if (session.isAdminParty()) {
- session.trigger('authenticated');
- deferred.resolve();
- } else if (session.matchesRoles(roles)) {
- session.trigger('authenticated');
- deferred.resolve();
- } else {
- deferred.reject();
- }
-
- return [deferred];
- };
-
- var authDenied = function () {
- var url = window.location.hash.replace('#', '');
- var pattern = /login\?urlback=/g;
+import app from "../../app";
+import FauxtonAPI from "../../core/api";
+import Auth from "./routes";
+import "./assets/less/auth.less";
+
+Auth.session = new Auth.Session();
+FauxtonAPI.setSession(Auth.session);
+app.session = Auth.session;
+
+Auth.initialize = function () {
+
+ FauxtonAPI.addHeaderLink({
+ id: 'auth',
+ title: 'Login',
+ href: '#login',
+ icon: 'fonticon-user',
+ bottomNav: true
+ });
+
+ Auth.session.on('change', function () {
+ var session = Auth.session;
+ var link = {};
+
+ if (session.isAdminParty()) {
+ link = {
+ id: 'auth',
+ title: 'Admin Party!',
+ href: '#createAdmin',
+ icon: 'fonticon-user',
+ bottomNav: true
+ };
+ } else if (session.isLoggedIn()) {
+ link = {
+ id: 'auth',
+ title: session.user().name,
+ href: '#changePassword',
+ icon: 'fonticon-user',
+ bottomNav: true
+ };
+
+ // ensure the footer link is removed before adding it
+ FauxtonAPI.removeHeaderLink({ id: 'logout', footerNav: true });
+ FauxtonAPI.addHeaderLink({
+ id: 'logout',
+ footerNav: true,
+ href: '#logout',
+ title: 'Logout',
+ icon: '',
+ className: 'logout'
+ });
+ } else {
+ link = {
+ id: 'auth',
+ title: 'Login',
+ href: '#login',
+ icon: 'fonticon-user',
+ bottomNav: true
+ };
+ FauxtonAPI.removeHeaderLink({ id: 'logout', footerNav: true });
+ }
+ FauxtonAPI.updateHeaderLink(link);
+ });
+
+ Auth.session.fetchUser().then(function () {
+ Auth.session.trigger('change');
+ });
+
+ var auth = function (session, roles) {
+ var deferred = $.Deferred();
+
+ if (session.isAdminParty()) {
+ session.trigger('authenticated');
+ deferred.resolve();
+ } else if (session.matchesRoles(roles)) {
+ session.trigger('authenticated');
+ deferred.resolve();
+ } else {
+ deferred.reject();
+ }
+
+ return [deferred];
+ };
- if (pattern.test(url)) {
- url = url.replace('login?urlback=', '');
- }
- FauxtonAPI.navigate('/login?urlback=' + url, { replace: true });
- };
+ var authDenied = function () {
+ var url = window.location.hash.replace('#', '');
+ var pattern = /login\?urlback=/g;
- FauxtonAPI.auth.registerAuth(auth);
- FauxtonAPI.auth.registerAuthDenied(authDenied);
+ if (pattern.test(url)) {
+ url = url.replace('login?urlback=', '');
+ }
+ FauxtonAPI.navigate('/login?urlback=' + url, { replace: true });
};
- return Auth;
-});
+ FauxtonAPI.auth.registerAuth(auth);
+ FauxtonAPI.auth.registerAuthDenied(authDenied);
+};
+
+export default Auth;
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/components.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/auth/components.react.jsx b/app/addons/auth/components.react.jsx
index fc9d29a..fda85de 100644
--- a/app/addons/auth/components.react.jsx
+++ b/app/addons/auth/components.react.jsx
@@ -10,306 +10,301 @@
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../app',
- '../../core/api',
- 'react',
- 'react-dom',
- './stores',
- './actions'
-], function (app, FauxtonAPI, React, ReactDOM, AuthStores, AuthActions) {
-
- var changePasswordStore = AuthStores.changePasswordStore;
- var createAdminStore = AuthStores.createAdminStore;
- var createAdminSidebarStore = AuthStores.createAdminSidebarStore;
-
-
- var LoginForm = React.createClass({
- propTypes: {
- urlBack: React.PropTypes.string.isRequired
- },
-
- getInitialState: function () {
- return {
- username: '',
- password: ''
- };
- },
-
- getDefaultProps: function () {
- return {
- urlBack: '',
-
- // for testing purposes only
- testBlankUsername: null,
- testBlankPassword: null
- };
- },
-
- onInputChange: function (e) {
- var change = (e.target.name === 'name') ? { username: e.target.value } : { password: e.target.value };
- this.setState(change);
- },
-
- submit: function (e) {
- e.preventDefault();
-
- if (!this.checkUnrecognizedAutoFill()) {
- this.login(this.state.username, this.state.password);
- }
- },
-
- // Safari has a bug where autofill doesn't trigger a change event. This checks for the condition where the state
- // and form fields have a mismatch. See: https://issues.apache.org/jira/browse/COUCHDB-2829
- checkUnrecognizedAutoFill: function () {
- if (this.state.username !== '' || this.state.password !== '') {
- return false;
- }
- var username = (this.props.testBlankUsername) ? this.props.testBlankUsername : ReactDOM.findDOMNode(this.refs.username).value;
- var password = (this.props.testBlankPassword) ? this.props.testBlankPassword : ReactDOM.findDOMNode(this.refs.password).value;
- this.setState({ username: username, password: password }); // doesn't set immediately, hence separate login() call
- this.login(username, password);
-
- return true;
- },
-
- login: function (username, password) {
- AuthActions.login(username, password, this.props.urlBack);
- },
-
- componentDidMount: function () {
- ReactDOM.findDOMNode(this.refs.username).focus();
- },
-
- render: function () {
- return (
- <div className="couch-login-wrapper">
- <div className="row-fluid">
- <div className="span12">
- <form id="login" onSubmit={this.submit}>
- <p className="help-block">
- Enter your username and password.
- </p>
- <input id="username" type="text" name="name" ref="username" placeholder="Username" size="24"
- onChange={this.onInputChange} value={this.state.username} />
- <br/>
- <input id="password" type="password" name="password" ref="password" placeholder="Password" size="24"
- onChange={this.onInputChange} value={this.state.password} />
- <br/>
- <button id="submit" className="btn btn-success" type="submit">Log In</button>
- </form>
- </div>
- </div>
- </div>
- );
+import app from "../../app";
+import FauxtonAPI from "../../core/api";
+import React from "react";
+import ReactDOM from "react-dom";
+import AuthStores from "./stores";
+import AuthActions from "./actions";
+
+var changePasswordStore = AuthStores.changePasswordStore;
+var createAdminStore = AuthStores.createAdminStore;
+var createAdminSidebarStore = AuthStores.createAdminSidebarStore;
+
+
+var LoginForm = React.createClass({
+ propTypes: {
+ urlBack: React.PropTypes.string.isRequired
+ },
+
+ getInitialState: function () {
+ return {
+ username: '',
+ password: ''
+ };
+ },
+
+ getDefaultProps: function () {
+ return {
+ urlBack: '',
+
+ // for testing purposes only
+ testBlankUsername: null,
+ testBlankPassword: null
+ };
+ },
+
+ onInputChange: function (e) {
+ var change = (e.target.name === 'name') ? { username: e.target.value } : { password: e.target.value };
+ this.setState(change);
+ },
+
+ submit: function (e) {
+ e.preventDefault();
+
+ if (!this.checkUnrecognizedAutoFill()) {
+ this.login(this.state.username, this.state.password);
}
- });
-
-
- var ChangePasswordForm = React.createClass({
- getInitialState: function () {
- return this.getStoreState();
- },
-
- getStoreState: function () {
- return {
- password: changePasswordStore.getChangePassword(),
- passwordConfirm: changePasswordStore.getChangePasswordConfirm()
- };
- },
-
- onChange: function () {
- this.setState(this.getStoreState());
- },
-
- onChangePassword: function (e) {
- AuthActions.updateChangePasswordField(e.target.value);
- },
-
- onChangePasswordConfirm: function (e) {
- AuthActions.updateChangePasswordConfirmField(e.target.value);
- },
-
- componentDidMount: function () {
- ReactDOM.findDOMNode(this.refs.password).focus();
- changePasswordStore.on('change', this.onChange, this);
- },
-
- componentWillUnmount: function () {
- changePasswordStore.off('change', this.onChange);
- },
-
- changePassword: function (e) {
- e.preventDefault();
- AuthActions.changePassword(this.state.password, this.state.passwordConfirm);
- },
-
- render: function () {
- return (
- <div className="auth-page">
- <h3>Change Password</h3>
-
- <form id="change-password" onSubmit={this.changePassword}>
- <p>
- Enter your new password.
- </p>
-
- <input id="password" type="password" ref="password" name="password" placeholder="Password"
- size="24" onChange={this.onChangePassword} value={this.state.password} />
- <br />
- <input id="password-confirm" type="password" name="password_confirm" placeholder= "Verify Password"
- size="24" onChange={this.onChangePasswordConfirm} value={this.state.passwordConfirm} />
-
- <br />
- <p>
- <button type="submit" className="btn btn-primary">Change</button>
- </p>
- </form>
- </div>
- );
+ },
+
+ // Safari has a bug where autofill doesn't trigger a change event. This checks for the condition where the state
+ // and form fields have a mismatch. See: https://issues.apache.org/jira/browse/COUCHDB-2829
+ checkUnrecognizedAutoFill: function () {
+ if (this.state.username !== '' || this.state.password !== '') {
+ return false;
}
- });
-
-
- var CreateAdminForm = React.createClass({
- propTypes: {
- loginAfter: React.PropTypes.bool.isRequired
- },
-
- getInitialState: function () {
- return this.getStoreState();
- },
-
- getStoreState: function () {
- return {
- username: createAdminStore.getUsername(),
- password: createAdminStore.getPassword()
- };
- },
-
- onChange: function () {
- this.setState(this.getStoreState());
- },
-
- getDefaultProps: function () {
- return {
- loginAfter: ''
- };
- },
-
- onChangeUsername: function (e) {
- AuthActions.updateCreateAdminUsername(e.target.value);
- },
-
- onChangePassword: function (e) {
- AuthActions.updateCreateAdminPassword(e.target.value);
- },
-
- componentDidMount: function () {
- ReactDOM.findDOMNode(this.refs.username).focus();
- createAdminStore.on('change', this.onChange, this);
- },
-
- componentWillUnmount: function () {
- createAdminStore.off('change', this.onChange);
- },
-
- createAdmin: function (e) {
- e.preventDefault();
- AuthActions.createAdmin(this.state.username, this.state.password, this.props.loginAfter);
- },
-
- render: function () {
- return (
- <div className="auth-page">
- <h3>Create Admins</h3>
+ var username = (this.props.testBlankUsername) ? this.props.testBlankUsername : ReactDOM.findDOMNode(this.refs.username).value;
+ var password = (this.props.testBlankPassword) ? this.props.testBlankPassword : ReactDOM.findDOMNode(this.refs.password).value;
+ this.setState({ username: username, password: password }); // doesn't set immediately, hence separate login() call
+ this.login(username, password);
+
+ return true;
+ },
+
+ login: function (username, password) {
+ AuthActions.login(username, password, this.props.urlBack);
+ },
+
+ componentDidMount: function () {
+ ReactDOM.findDOMNode(this.refs.username).focus();
+ },
+
+ render: function () {
+ return (
+ <div className="couch-login-wrapper">
+ <div className="row-fluid">
+ <div className="span12">
+ <form id="login" onSubmit={this.submit}>
+ <p className="help-block">
+ Enter your username and password.
+ </p>
+ <input id="username" type="text" name="name" ref="username" placeholder="Username" size="24"
+ onChange={this.onInputChange} value={this.state.username} />
+ <br/>
+ <input id="password" type="password" name="password" ref="password" placeholder="Password" size="24"
+ onChange={this.onInputChange} value={this.state.password} />
+ <br/>
+ <button id="submit" className="btn btn-success" type="submit">Log In</button>
+ </form>
+ </div>
+ </div>
+ </div>
+ );
+ }
+});
+
+
+var ChangePasswordForm = React.createClass({
+ getInitialState: function () {
+ return this.getStoreState();
+ },
+
+ getStoreState: function () {
+ return {
+ password: changePasswordStore.getChangePassword(),
+ passwordConfirm: changePasswordStore.getChangePasswordConfirm()
+ };
+ },
+
+ onChange: function () {
+ this.setState(this.getStoreState());
+ },
+
+ onChangePassword: function (e) {
+ AuthActions.updateChangePasswordField(e.target.value);
+ },
+
+ onChangePasswordConfirm: function (e) {
+ AuthActions.updateChangePasswordConfirmField(e.target.value);
+ },
+
+ componentDidMount: function () {
+ ReactDOM.findDOMNode(this.refs.password).focus();
+ changePasswordStore.on('change', this.onChange, this);
+ },
+ componentWillUnmount: function () {
+ changePasswordStore.off('change', this.onChange);
+ },
+
+ changePassword: function (e) {
+ e.preventDefault();
+ AuthActions.changePassword(this.state.password, this.state.passwordConfirm);
+ },
+
+ render: function () {
+ return (
+ <div className="auth-page">
+ <h3>Change Password</h3>
+
+ <form id="change-password" onSubmit={this.changePassword}>
<p>
- Before a server admin is configured, all clients have admin privileges. This is fine when
- HTTP access is restricted to trusted users. <strong>If end-users will be accessing this
- CouchDB, you must create an admin account to prevent accidental (or malicious) data
- loss.</strong>
+ Enter your new password.
</p>
+
+ <input id="password" type="password" ref="password" name="password" placeholder="Password"
+ size="24" onChange={this.onChangePassword} value={this.state.password} />
+ <br />
+ <input id="password-confirm" type="password" name="password_confirm" placeholder= "Verify Password"
+ size="24" onChange={this.onChangePasswordConfirm} value={this.state.passwordConfirm} />
+
+ <br />
<p>
- Server admins can create and destroy databases, install and update _design documents, run
- the test suite, and edit all aspects of CouchDB configuration.
+ <button type="submit" className="btn btn-primary">Change</button>
</p>
+ </form>
+ </div>
+ );
+ }
+});
- <form id="create-admin-form" onSubmit={this.createAdmin}>
- <input id="username" type="text" ref="username" name="name" placeholder="Username" size="24"
- onChange={this.onChangeUsername} />
- <br/>
- <input id="password" type="password" name="password" placeholder= "Password" size="24"
- onChange={this.onChangePassword} />
- <p>
- Non-admin users have read and write access to all databases, which
- are controlled by validation functions. CouchDB can be configured to block all
- access to anonymous users.
- </p>
- <button type="submit" id="create-admin" className="btn btn-primary">Create Admin</button>
- </form>
- </div>
- );
- }
- });
-
-
- var CreateAdminSidebar = React.createClass({
- getInitialState: function () {
- return this.getStoreState();
- },
-
- getStoreState: function () {
- return {
- selectedPage: createAdminSidebarStore.getSelectedPage()
- };
- },
-
- onChange: function () {
- this.setState(this.getStoreState());
- },
-
- componentDidMount: function () {
- createAdminSidebarStore.on('change', this.onChange, this);
- },
-
- componentWillUnmount: function () {
- createAdminSidebarStore.off('change', this.onChange);
- },
-
- selectPage: function (e) {
- var newPage = e.target.href.split('#')[1];
- AuthActions.selectPage(newPage);
- },
-
- render: function () {
- var user = FauxtonAPI.session.user();
- var userName = _.isNull(user) ? '' : FauxtonAPI.session.user().name;
-
- return (
- <div className="sidenav">
- <header className="row-fluid">
- <h3>{userName}</h3>
- </header>
- <ul className="nav nav-list" onClick={this.selectPage}>
- <li className={this.state.selectedPage === 'changePassword' ? 'active' : ''} data-page="changePassword">
- <a href="#changePassword">Change Password</a>
- </li>
- <li className={this.state.selectedPage === 'addAdmin' ? 'active' : ''} data-page="addAdmin">
- <a href="#addAdmin">Create Admins</a>
- </li>
- </ul>
- </div>
- );
- }
- });
- return {
- LoginForm: LoginForm,
- ChangePasswordForm: ChangePasswordForm,
- CreateAdminForm: CreateAdminForm,
- CreateAdminSidebar: CreateAdminSidebar
- };
+var CreateAdminForm = React.createClass({
+ propTypes: {
+ loginAfter: React.PropTypes.bool.isRequired
+ },
+
+ getInitialState: function () {
+ return this.getStoreState();
+ },
+
+ getStoreState: function () {
+ return {
+ username: createAdminStore.getUsername(),
+ password: createAdminStore.getPassword()
+ };
+ },
+
+ onChange: function () {
+ this.setState(this.getStoreState());
+ },
+
+ getDefaultProps: function () {
+ return {
+ loginAfter: ''
+ };
+ },
+
+ onChangeUsername: function (e) {
+ AuthActions.updateCreateAdminUsername(e.target.value);
+ },
+
+ onChangePassword: function (e) {
+ AuthActions.updateCreateAdminPassword(e.target.value);
+ },
+
+ componentDidMount: function () {
+ ReactDOM.findDOMNode(this.refs.username).focus();
+ createAdminStore.on('change', this.onChange, this);
+ },
+
+ componentWillUnmount: function () {
+ createAdminStore.off('change', this.onChange);
+ },
+
+ createAdmin: function (e) {
+ e.preventDefault();
+ AuthActions.createAdmin(this.state.username, this.state.password, this.props.loginAfter);
+ },
+
+ render: function () {
+ return (
+ <div className="auth-page">
+ <h3>Create Admins</h3>
+
+ <p>
+ Before a server admin is configured, all clients have admin privileges. This is fine when
+ HTTP access is restricted to trusted users. <strong>If end-users will be accessing this
+ CouchDB, you must create an admin account to prevent accidental (or malicious) data
+ loss.</strong>
+ </p>
+ <p>
+ Server admins can create and destroy databases, install and update _design documents, run
+ the test suite, and edit all aspects of CouchDB configuration.
+ </p>
+
+ <form id="create-admin-form" onSubmit={this.createAdmin}>
+ <input id="username" type="text" ref="username" name="name" placeholder="Username" size="24"
+ onChange={this.onChangeUsername} />
+ <br/>
+ <input id="password" type="password" name="password" placeholder= "Password" size="24"
+ onChange={this.onChangePassword} />
+ <p>
+ Non-admin users have read and write access to all databases, which
+ are controlled by validation functions. CouchDB can be configured to block all
+ access to anonymous users.
+ </p>
+ <button type="submit" id="create-admin" className="btn btn-primary">Create Admin</button>
+ </form>
+ </div>
+ );
+ }
+});
+var CreateAdminSidebar = React.createClass({
+ getInitialState: function () {
+ return this.getStoreState();
+ },
+
+ getStoreState: function () {
+ return {
+ selectedPage: createAdminSidebarStore.getSelectedPage()
+ };
+ },
+
+ onChange: function () {
+ this.setState(this.getStoreState());
+ },
+
+ componentDidMount: function () {
+ createAdminSidebarStore.on('change', this.onChange, this);
+ },
+
+ componentWillUnmount: function () {
+ createAdminSidebarStore.off('change', this.onChange);
+ },
+
+ selectPage: function (e) {
+ var newPage = e.target.href.split('#')[1];
+ AuthActions.selectPage(newPage);
+ },
+
+ render: function () {
+ var user = FauxtonAPI.session.user();
+ var userName = _.isNull(user) ? '' : FauxtonAPI.session.user().name;
+
+ return (
+ <div className="sidenav">
+ <header className="row-fluid">
+ <h3>{userName}</h3>
+ </header>
+ <ul className="nav nav-list" onClick={this.selectPage}>
+ <li className={this.state.selectedPage === 'changePassword' ? 'active' : ''} data-page="changePassword">
+ <a href="#changePassword">Change Password</a>
+ </li>
+ <li className={this.state.selectedPage === 'addAdmin' ? 'active' : ''} data-page="addAdmin">
+ <a href="#addAdmin">Create Admins</a>
+ </li>
+ </ul>
+ </div>
+ );
+ }
});
+
+export default {
+ LoginForm: LoginForm,
+ ChangePasswordForm: ChangePasswordForm,
+ CreateAdminForm: CreateAdminForm,
+ CreateAdminSidebar: CreateAdminSidebar
+};
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/resources.js b/app/addons/auth/resources.js
index 3732828..91f4456 100644
--- a/app/addons/auth/resources.js
+++ b/app/addons/auth/resources.js
@@ -10,204 +10,199 @@
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../app',
- '../../core/api',
- "../../core/couchdbSession"
-],
+import app from "../../app";
+import FauxtonAPI from "../../core/api";
+import CouchdbSession from "../../core/couchdbSession";
-function (app, FauxtonAPI, CouchdbSession) {
+var Auth = new FauxtonAPI.addon();
- var Auth = new FauxtonAPI.addon();
+var Admin = Backbone.Model.extend({
- var Admin = Backbone.Model.extend({
+ initialize: function (props, options) {
+ this.node = options.node;
+ },
- initialize: function (props, options) {
- this.node = options.node;
- },
-
- url: function () {
- if (!this.node) {
- throw new Error('no node set');
- }
+ url: function () {
+ if (!this.node) {
+ throw new Error('no node set');
+ }
- return app.host + '/_node/' + this.node + '/_config/admins/' + this.get('name');
- },
+ return app.host + '/_node/' + this.node + '/_config/admins/' + this.get('name');
+ },
- isNew: function () { return false; },
+ isNew: function () { return false; },
- sync: function (method, model, options) {
- var params = {
- url: model.url(),
- contentType: 'application/json',
- dataType: 'json',
- data: JSON.stringify(model.get('value'))
- };
+ sync: function (method, model, options) {
+ var params = {
+ url: model.url(),
+ contentType: 'application/json',
+ dataType: 'json',
+ data: JSON.stringify(model.get('value'))
+ };
- if (method === 'delete') {
- params.type = 'DELETE';
- } else {
- params.type = 'PUT';
- }
-
- return $.ajax(params);
+ if (method === 'delete') {
+ params.type = 'DELETE';
+ } else {
+ params.type = 'PUT';
}
- });
- Auth.Session = CouchdbSession.Session.extend({
- url: app.host + '/_session',
+ return $.ajax(params);
+ }
+});
- initialize: function (options) {
- if (!options) { options = {}; }
+Auth.Session = CouchdbSession.Session.extend({
+ url: app.host + '/_session',
- _.bindAll(this);
+ initialize: function (options) {
+ if (!options) { options = {}; }
- this.messages = _.extend({}, {
- missingCredentials: 'Username or password cannot be blank.',
- loggedIn: 'You have been logged in.',
- adminCreated: 'CouchDB admin created',
- changePassword: 'Your password has been updated.',
- adminCreationFailedPrefix: 'Could not create admin.'
- }, options.messages);
- },
+ _.bindAll(this);
- isAdminParty: function () {
- var userCtx = this.get('userCtx');
+ this.messages = _.extend({}, {
+ missingCredentials: 'Username or password cannot be blank.',
+ loggedIn: 'You have been logged in.',
+ adminCreated: 'CouchDB admin created',
+ changePassword: 'Your password has been updated.',
+ adminCreationFailedPrefix: 'Could not create admin.'
+ }, options.messages);
+ },
+ isAdminParty: function () {
+ var userCtx = this.get('userCtx');
- if (!userCtx.name && userCtx.roles.indexOf("_admin") > -1) {
- return true;
- }
- return false;
- },
+ if (!userCtx.name && userCtx.roles.indexOf("_admin") > -1) {
+ return true;
+ }
- isLoggedIn: function () {
- var userCtx = this.get('userCtx');
+ return false;
+ },
- if (!userCtx) { return false;}
- if (userCtx.name) {
- return true;
- }
+ isLoggedIn: function () {
+ var userCtx = this.get('userCtx');
- return false;
- },
+ if (!userCtx) { return false;}
+ if (userCtx.name) {
+ return true;
+ }
- userRoles: function () {
- var user = this.user();
+ return false;
+ },
- if (user && user.roles) {
- if (user.roles.indexOf('fx_loggedIn') === -1) {
- user.roles.push('fx_loggedIn');
- }
+ userRoles: function () {
+ var user = this.user();
- return user.roles;
+ if (user && user.roles) {
+ if (user.roles.indexOf('fx_loggedIn') === -1) {
+ user.roles.push('fx_loggedIn');
}
- return [];
- },
+ return user.roles;
+ }
- matchesRoles: function (roles) {
- if (roles.length === 0) {
- return true;
- }
+ return [];
+ },
- var numberMatchingRoles = _.intersection(this.userRoles(), roles).length;
+ matchesRoles: function (roles) {
+ if (roles.length === 0) {
+ return true;
+ }
- if (numberMatchingRoles > 0) {
- return true;
- }
+ var numberMatchingRoles = _.intersection(this.userRoles(), roles).length;
- return false;
- },
+ if (numberMatchingRoles > 0) {
+ return true;
+ }
- validateUser: function (username, password, msg) {
- if (_.isEmpty(username) || _.isEmpty(password)) {
- var deferred = FauxtonAPI.Deferred();
+ return false;
+ },
- deferred.rejectWith(this, [msg]);
- return deferred;
- }
- },
+ validateUser: function (username, password, msg) {
+ if (_.isEmpty(username) || _.isEmpty(password)) {
+ var deferred = FauxtonAPI.Deferred();
- validatePasswords: function (password, password_confirm, msg) {
- if (_.isEmpty(password) || _.isEmpty(password_confirm) || (password !== password_confirm)) {
- var deferred = FauxtonAPI.Deferred();
+ deferred.rejectWith(this, [msg]);
+ return deferred;
+ }
+ },
- deferred.rejectWith(this, [msg]);
- return deferred;
- }
- },
-
- createAdmin: function (username, password, login, node) {
- var errorPromise = this.validateUser(username, password, this.messages.missingCredentials);
-
- if (errorPromise) { return errorPromise; }
-
- var admin = new Admin({
- name: username,
- value: password
- }, {node: node});
-
- return admin.save().then(function () {
- if (login) {
- return this.login(username, password);
- }
-
- return this.fetchUser({forceFetch: true});
-
- }.bind(this));
- },
-
- login: function (username, password) {
- var errorPromise = this.validateUser(username, password, this.messages.missingCredentials);
-
- if (errorPromise) { return errorPromise; }
-
- return $.ajax({
- cache: false,
- type: "POST",
- url: app.host + "/_session",
- dataType: "json",
- data: {name: username, password: password}
- }).then(function () {
- return this.fetchUser({forceFetch: true});
- }.bind(this));
- },
-
- logout: function () {
- var that = this;
-
- return $.ajax({
- type: "DELETE",
- url: app.host + "/_session",
- dataType: "json",
- username : "_",
- password : "_"
- }).then(function () {
- return that.fetchUser({forceFetch: true });
- });
- },
-
- changePassword: function (password, confirmedPassword, node) {
- var errorMessage = 'Passwords do not match.';
- var errorPromise = this.validatePasswords(password, confirmedPassword, errorMessage);
-
- if (errorPromise) { return errorPromise; }
-
- var userName = this.get('userCtx').name;
- var admin = new Admin({
- name: userName,
- value: password
- }, {node: node});
-
- return admin.save().then(function () {
- return this.login(userName, password);
- }.bind(this));
+ validatePasswords: function (password, password_confirm, msg) {
+ if (_.isEmpty(password) || _.isEmpty(password_confirm) || (password !== password_confirm)) {
+ var deferred = FauxtonAPI.Deferred();
+
+ deferred.rejectWith(this, [msg]);
+ return deferred;
}
- });
+ },
+ createAdmin: function (username, password, login, node) {
+ var errorPromise = this.validateUser(username, password, this.messages.missingCredentials);
- return Auth;
+ if (errorPromise) { return errorPromise; }
+
+ var admin = new Admin({
+ name: username,
+ value: password
+ }, {node: node});
+
+ return admin.save().then(function () {
+ if (login) {
+ return this.login(username, password);
+ }
+
+ return this.fetchUser({forceFetch: true});
+
+ }.bind(this));
+ },
+
+ login: function (username, password) {
+ var errorPromise = this.validateUser(username, password, this.messages.missingCredentials);
+
+ if (errorPromise) { return errorPromise; }
+
+ return $.ajax({
+ cache: false,
+ type: "POST",
+ url: app.host + "/_session",
+ dataType: "json",
+ data: {name: username, password: password}
+ }).then(function () {
+ return this.fetchUser({forceFetch: true});
+ }.bind(this));
+ },
+
+ logout: function () {
+ var that = this;
+
+ return $.ajax({
+ type: "DELETE",
+ url: app.host + "/_session",
+ dataType: "json",
+ username : "_",
+ password : "_"
+ }).then(function () {
+ return that.fetchUser({forceFetch: true });
+ });
+ },
+
+ changePassword: function (password, confirmedPassword, node) {
+ var errorMessage = 'Passwords do not match.';
+ var errorPromise = this.validatePasswords(password, confirmedPassword, errorMessage);
+
+ if (errorPromise) { return errorPromise; }
+
+ var userName = this.get('userCtx').name;
+ var admin = new Admin({
+ name: userName,
+ value: password
+ }, {node: node});
+
+ return admin.save().then(function () {
+ return this.login(userName, password);
+ }.bind(this));
+ }
});
+
+
+export default Auth;
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/routes.js b/app/addons/auth/routes.js
index 8b7eb6d..2ba3931 100644
--- a/app/addons/auth/routes.js
+++ b/app/addons/auth/routes.js
@@ -10,108 +10,103 @@
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../app',
- '../../core/api',
- './resources',
- './actions',
- './components.react',
- '../cluster/cluster.actions'
-],
-
-function (app, FauxtonAPI, Auth, AuthActions, Components, ClusterActions) {
-
- var AuthRouteObject = FauxtonAPI.RouteObject.extend({
- layout: 'one_pane',
-
- routes: {
- 'login?*extra': 'login',
- 'login': 'login',
- 'logout': 'logout',
- 'createAdmin': 'checkNodes',
- 'createAdmin/:node': 'createAdminForNode'
- },
- disableLoader: true,
- hideNotificationCenter: true,
-
- checkNodes: function () {
- ClusterActions.navigateToNodeBasedOnNodeCount('/createAdmin/');
- },
+import app from "../../app";
+import FauxtonAPI from "../../core/api";
+import Auth from "./resources";
+import AuthActions from "./actions";
+import Components from "./components.react";
+import ClusterActions from "../cluster/cluster.actions";
+
+var AuthRouteObject = FauxtonAPI.RouteObject.extend({
+ layout: 'one_pane',
+
+ routes: {
+ 'login?*extra': 'login',
+ 'login': 'login',
+ 'logout': 'logout',
+ 'createAdmin': 'checkNodes',
+ 'createAdmin/:node': 'createAdminForNode'
+ },
+ disableLoader: true,
+ hideNotificationCenter: true,
+
+ checkNodes: function () {
+ ClusterActions.navigateToNodeBasedOnNodeCount('/createAdmin/');
+ },
+
+ login: function () {
+ this.crumbs = [{ name: 'Log In to CouchDB', link: "#" }];
+ this.setComponent('#dashboard-content', Components.LoginForm, { urlBack: app.getParams().urlback });
+ },
+
+ logout: function () {
+ FauxtonAPI.addNotification({ msg: 'You have been logged out.' });
+ FauxtonAPI.session.logout().then(function () {
+ FauxtonAPI.navigate('/');
+ });
+ },
+
+ createAdminForNode: function () {
+ ClusterActions.fetchNodes();
+ this.crumbs = [{name: 'Create Admin', link: '#'}];
+ this.setComponent('#dashboard-content', Components.CreateAdminForm, { loginAfter: true });
+ }
+});
- login: function () {
- this.crumbs = [{ name: 'Log In to CouchDB', link: "#" }];
- this.setComponent('#dashboard-content', Components.LoginForm, { urlBack: app.getParams().urlback });
- },
- logout: function () {
- FauxtonAPI.addNotification({ msg: 'You have been logged out.' });
- FauxtonAPI.session.logout().then(function () {
- FauxtonAPI.navigate('/');
- });
- },
+var UserRouteObject = FauxtonAPI.RouteObject.extend({
+ layout: 'with_sidebar',
- createAdminForNode: function () {
- ClusterActions.fetchNodes();
- this.crumbs = [{name: 'Create Admin', link: '#'}];
- this.setComponent('#dashboard-content', Components.CreateAdminForm, { loginAfter: true });
- }
- });
-
-
- var UserRouteObject = FauxtonAPI.RouteObject.extend({
- layout: 'with_sidebar',
-
- routes: {
- 'changePassword': {
- route: 'checkNodesForPasswordChange',
- roles: ['fx_loggedIn']
- },
- 'changePassword/:node': {
- route: 'changePassword',
- roles: ['fx_loggedIn']
- },
- 'addAdmin': {
- route: 'checkNodesForAddAdmin',
- roles: ['_admin']
- },
- 'addAdmin/:node': {
- route: 'addAdmin',
- roles: ['_admin']
- }
+ routes: {
+ 'changePassword': {
+ route: 'checkNodesForPasswordChange',
+ roles: ['fx_loggedIn']
},
-
- checkNodesForPasswordChange: function () {
- ClusterActions.navigateToNodeBasedOnNodeCount('/changePassword/');
+ 'changePassword/:node': {
+ route: 'changePassword',
+ roles: ['fx_loggedIn']
},
-
- checkNodesForAddAdmin: function () {
- ClusterActions.navigateToNodeBasedOnNodeCount('/addAdmin/');
+ 'addAdmin': {
+ route: 'checkNodesForAddAdmin',
+ roles: ['_admin']
},
+ 'addAdmin/:node': {
+ route: 'addAdmin',
+ roles: ['_admin']
+ }
+ },
- selectedHeader: function () {
- return FauxtonAPI.session.user().name;
- },
+ checkNodesForPasswordChange: function () {
+ ClusterActions.navigateToNodeBasedOnNodeCount('/changePassword/');
+ },
- initialize: function () {
- this.setComponent('#sidebar-content', Components.CreateAdminSidebar);
- },
+ checkNodesForAddAdmin: function () {
+ ClusterActions.navigateToNodeBasedOnNodeCount('/addAdmin/');
+ },
- changePassword: function () {
- ClusterActions.fetchNodes();
- AuthActions.selectPage('changePassword');
- this.setComponent('#dashboard-content', Components.ChangePasswordForm);
- },
+ selectedHeader: function () {
+ return FauxtonAPI.session.user().name;
+ },
- addAdmin: function () {
- ClusterActions.fetchNodes();
- AuthActions.selectPage('addAdmin');
- this.setComponent('#dashboard-content', Components.CreateAdminForm, { loginAfter: false });
- },
+ initialize: function () {
+ this.setComponent('#sidebar-content', Components.CreateAdminSidebar);
+ },
- crumbs: [{name: 'User Management', link: '#'}]
- });
+ changePassword: function () {
+ ClusterActions.fetchNodes();
+ AuthActions.selectPage('changePassword');
+ this.setComponent('#dashboard-content', Components.ChangePasswordForm);
+ },
- Auth.RouteObjects = [AuthRouteObject, UserRouteObject];
+ addAdmin: function () {
+ ClusterActions.fetchNodes();
+ AuthActions.selectPage('addAdmin');
+ this.setComponent('#dashboard-content', Components.CreateAdminForm, { loginAfter: false });
+ },
- return Auth;
+ crumbs: [{name: 'User Management', link: '#'}]
});
+
+Auth.RouteObjects = [AuthRouteObject, UserRouteObject];
+
+export default Auth;
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/stores.js
----------------------------------------------------------------------
diff --git a/app/addons/auth/stores.js b/app/addons/auth/stores.js
index f2142b7..25ef23a 100644
--- a/app/addons/auth/stores.js
+++ b/app/addons/auth/stores.js
@@ -10,162 +10,158 @@
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../app',
- '../../core/api',
- './actiontypes'
-], function (app, FauxtonAPI, ActionTypes) {
-
-
- // Not thrilled with this. The sole purpose of these next two stores is because the Create Admin + Change Password
- // forms need to clear after a successful post. Since those events occur in actions.js, we need a way to tell the
- // component to update + clear the fields. That's why all this code exists.
-
- var ChangePasswordStore = FauxtonAPI.Store.extend({
- initialize: function () {
- this.reset();
- },
-
- reset: function () {
- this._changePassword = '';
- this._changePasswordConfirm = '';
- },
-
- getChangePassword: function () {
- return this._changePassword;
- },
-
- getChangePasswordConfirm: function () {
- return this._changePasswordConfirm;
- },
-
- setChangePassword: function (val) {
- this._changePassword = val;
- },
-
- setChangePasswordConfirm: function (val) {
- this._changePasswordConfirm = val;
- },
-
- dispatch: function (action) {
- switch (action.type) {
-
- case ActionTypes.AUTH_CLEAR_CHANGE_PWD_FIELDS:
- this.reset();
- this.triggerChange();
- break;
-
- case ActionTypes.AUTH_UPDATE_CHANGE_PWD_FIELD:
- this.setChangePassword(action.value);
- this.triggerChange();
- break;
-
- case ActionTypes.AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD:
- this.setChangePasswordConfirm(action.value);
- this.triggerChange();
- break;
-
- default:
- return;
- }
- }
- });
-
- var changePasswordStore = new ChangePasswordStore();
- changePasswordStore.dispatchToken = FauxtonAPI.dispatcher.register(changePasswordStore.dispatch.bind(changePasswordStore));
-
-
- var CreateAdminStore = FauxtonAPI.Store.extend({
- initialize: function () {
- this.reset();
- },
-
- reset: function () {
- this._username = '';
- this._password = '';
- },
-
- getUsername: function () {
- return this._username;
- },
-
- getPassword: function () {
- return this._password;
- },
-
- setUsername: function (val) {
- this._username = val;
- },
-
- setPassword: function (val) {
- this._password = val;
- },
-
- dispatch: function (action) {
- switch (action.type) {
- case ActionTypes.AUTH_CLEAR_CREATE_ADMIN_FIELDS:
- this.reset();
- this.triggerChange();
- break;
-
- case ActionTypes.AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD:
- this.setUsername(action.value);
- this.triggerChange();
- break;
-
- case ActionTypes.AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD:
- this.setPassword(action.value);
- this.triggerChange();
- break;
-
- default:
- return;
- }
+import app from "../../app";
+import FauxtonAPI from "../../core/api";
+import ActionTypes from "./actiontypes";
+
+
+// Not thrilled with this. The sole purpose of these next two stores is because the Create Admin + Change Password
+// forms need to clear after a successful post. Since those events occur in actions.js, we need a way to tell the
+// component to update + clear the fields. That's why all this code exists.
+
+var ChangePasswordStore = FauxtonAPI.Store.extend({
+ initialize: function () {
+ this.reset();
+ },
+
+ reset: function () {
+ this._changePassword = '';
+ this._changePasswordConfirm = '';
+ },
+
+ getChangePassword: function () {
+ return this._changePassword;
+ },
+
+ getChangePasswordConfirm: function () {
+ return this._changePasswordConfirm;
+ },
+
+ setChangePassword: function (val) {
+ this._changePassword = val;
+ },
+
+ setChangePasswordConfirm: function (val) {
+ this._changePasswordConfirm = val;
+ },
+
+ dispatch: function (action) {
+ switch (action.type) {
+
+ case ActionTypes.AUTH_CLEAR_CHANGE_PWD_FIELDS:
+ this.reset();
+ this.triggerChange();
+ break;
+
+ case ActionTypes.AUTH_UPDATE_CHANGE_PWD_FIELD:
+ this.setChangePassword(action.value);
+ this.triggerChange();
+ break;
+
+ case ActionTypes.AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD:
+ this.setChangePasswordConfirm(action.value);
+ this.triggerChange();
+ break;
+
+ default:
+ return;
}
- });
+ }
+});
+
+var changePasswordStore = new ChangePasswordStore();
+changePasswordStore.dispatchToken = FauxtonAPI.dispatcher.register(changePasswordStore.dispatch.bind(changePasswordStore));
+
+
+var CreateAdminStore = FauxtonAPI.Store.extend({
+ initialize: function () {
+ this.reset();
+ },
- var createAdminStore = new CreateAdminStore();
- createAdminStore.dispatchToken = FauxtonAPI.dispatcher.register(createAdminStore.dispatch.bind(createAdminStore));
+ reset: function () {
+ this._username = '';
+ this._password = '';
+ },
+ getUsername: function () {
+ return this._username;
+ },
- var CreateAdminSidebarStore = FauxtonAPI.Store.extend({
- initialize: function () {
- this.reset();
- },
+ getPassword: function () {
+ return this._password;
+ },
- reset: function () {
- this._selectedPage = 'changePassword';
- },
+ setUsername: function (val) {
+ this._username = val;
+ },
- getSelectedPage: function () {
- return this._selectedPage;
- },
+ setPassword: function (val) {
+ this._password = val;
+ },
- setSelectedPage: function (val) {
- this._selectedPage = val;
- },
+ dispatch: function (action) {
+ switch (action.type) {
+ case ActionTypes.AUTH_CLEAR_CREATE_ADMIN_FIELDS:
+ this.reset();
+ this.triggerChange();
+ break;
- dispatch: function (action) {
- switch (action.type) {
- case ActionTypes.AUTH_SELECT_PAGE:
- this.setSelectedPage(action.page);
- this.triggerChange();
- break;
+ case ActionTypes.AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD:
+ this.setUsername(action.value);
+ this.triggerChange();
+ break;
- default:
- return;
- }
+ case ActionTypes.AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD:
+ this.setPassword(action.value);
+ this.triggerChange();
+ break;
+
+ default:
+ return;
}
- });
+ }
+});
+
+var createAdminStore = new CreateAdminStore();
+createAdminStore.dispatchToken = FauxtonAPI.dispatcher.register(createAdminStore.dispatch.bind(createAdminStore));
- var createAdminSidebarStore = new CreateAdminSidebarStore();
- createAdminSidebarStore.dispatchToken = FauxtonAPI.dispatcher.register(createAdminSidebarStore.dispatch.bind(createAdminSidebarStore));
+var CreateAdminSidebarStore = FauxtonAPI.Store.extend({
+ initialize: function () {
+ this.reset();
+ },
- return {
- changePasswordStore: changePasswordStore,
- createAdminStore: createAdminStore,
- createAdminSidebarStore: createAdminSidebarStore
- };
+ reset: function () {
+ this._selectedPage = 'changePassword';
+ },
+ getSelectedPage: function () {
+ return this._selectedPage;
+ },
+
+ setSelectedPage: function (val) {
+ this._selectedPage = val;
+ },
+
+ dispatch: function (action) {
+ switch (action.type) {
+ case ActionTypes.AUTH_SELECT_PAGE:
+ this.setSelectedPage(action.page);
+ this.triggerChange();
+ break;
+
+ default:
+ return;
+ }
+ }
});
+
+var createAdminSidebarStore = new CreateAdminSidebarStore();
+createAdminSidebarStore.dispatchToken = FauxtonAPI.dispatcher.register(createAdminSidebarStore.dispatch.bind(createAdminSidebarStore));
+
+
+export default {
+ changePasswordStore: changePasswordStore,
+ createAdminStore: createAdminStore,
+ createAdminSidebarStore: createAdminSidebarStore
+};
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/0ca35da7/app/addons/auth/test/auth.componentsSpec.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/auth/test/auth.componentsSpec.react.jsx b/app/addons/auth/test/auth.componentsSpec.react.jsx
index 23d4c55..81eebfe 100644
--- a/app/addons/auth/test/auth.componentsSpec.react.jsx
+++ b/app/addons/auth/test/auth.componentsSpec.react.jsx
@@ -9,143 +9,139 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
-define([
- '../../../core/api',
- 'react',
- 'react-dom',
- '../../../../test/mocha/testUtils',
- '../components.react',
- '../stores',
- '../actions',
- 'react-addons-test-utils',
- 'sinon'
-], function (FauxtonAPI, React, ReactDOM, utils, Components, Stores, Actions, TestUtils, sinon) {
- var assert = utils.assert;
-
- var createAdminSidebarStore = Stores.createAdminSidebarStore;
-
- describe('Auth -- Components', function () {
-
- describe('LoginForm', function () {
- var container, loginForm, stub;
-
- beforeEach(function () {
- stub = sinon.stub(Actions, 'login');
- container = document.createElement('div');
- });
-
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
- createAdminSidebarStore.reset();
- Actions.login.restore();
- });
-
- it('should trigger login event when form submitted', function () {
- loginForm = TestUtils.renderIntoDocument(<Components.LoginForm />, container);
- TestUtils.Simulate.submit($(ReactDOM.findDOMNode(loginForm)).find('#login')[0]);
- assert.ok(stub.calledOnce);
- });
-
- it('in case of nothing in state, should pass actual values to Actions.login()', function () {
- var username = 'bob';
- var password = 'smith';
-
- loginForm = TestUtils.renderIntoDocument(
- <Components.LoginForm
- testBlankUsername={username}
- testBlankPassword={password}
- />, container);
-
- TestUtils.Simulate.submit($(ReactDOM.findDOMNode(loginForm)).find('#login')[0]);
- assert.ok(stub.calledOnce);
-
- // confirm Actions.login() received the values that weren't in the DOM
- assert.equal(stub.args[0][0], username);
- assert.equal(stub.args[0][1], password);
- });
-
- });
-
- describe('ChangePasswordForm', function () {
- var container, changePasswordForm;
-
- beforeEach(function () {
- container = document.createElement('div');
- changePasswordForm = TestUtils.renderIntoDocument(<Components.ChangePasswordForm />, container);
- utils.restore(Actions.changePassword);
- });
-
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
- });
-
- it('should call action to update password on field change', function () {
- var spy = sinon.spy(Actions, 'updateChangePasswordField');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(changePasswordForm)).find('#password')[0], { target: { value: 'bobsyouruncle' }});
- assert.ok(spy.calledOnce);
- });
-
- it('should call action to update password confirm on field change', function () {
- var spy = sinon.spy(Actions, 'updateChangePasswordConfirmField');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(changePasswordForm)).find('#password-confirm')[0], { target: { value: 'hotdiggity' }});
- assert.ok(spy.calledOnce);
- });
-
- it('should call action to submit form', function () {
- var stub = sinon.stub(Actions, 'changePassword', function () {});
- TestUtils.Simulate.submit($(ReactDOM.findDOMNode(changePasswordForm)).find('#change-password')[0]);
- assert.ok(stub.calledOnce);
- });
- });
-
- describe('CreateAdminForm', function () {
- var container, createAdminForm;
-
- beforeEach(function () {
- container = document.createElement('div');
- createAdminForm = TestUtils.renderIntoDocument(<Components.CreateAdminForm loginAfter={false} />, container);
- });
-
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
- });
-
- it('should call action to update username on field change', function () {
- var spy = sinon.spy(Actions, 'updateCreateAdminUsername');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(createAdminForm)).find('#username')[0], { target: { value: 'catsmeow' }});
- assert.ok(spy.calledOnce);
- });
+import FauxtonAPI from "../../../core/api";
+import React from "react";
+import ReactDOM from "react-dom";
+import utils from "../../../../test/mocha/testUtils";
+import Components from "../components.react";
+import Stores from "../stores";
+import Actions from "../actions";
+import TestUtils from "react-addons-test-utils";
+import sinon from "sinon";
+var assert = utils.assert;
+
+var createAdminSidebarStore = Stores.createAdminSidebarStore;
+
+describe('Auth -- Components', function () {
+
+ describe('LoginForm', function () {
+ var container, loginForm, stub;
+
+ beforeEach(function () {
+ stub = sinon.stub(Actions, 'login');
+ container = document.createElement('div');
+ });
+
+ afterEach(function () {
+ ReactDOM.unmountComponentAtNode(container);
+ createAdminSidebarStore.reset();
+ Actions.login.restore();
+ });
+
+ it('should trigger login event when form submitted', function () {
+ loginForm = TestUtils.renderIntoDocument(<Components.LoginForm />, container);
+ TestUtils.Simulate.submit($(ReactDOM.findDOMNode(loginForm)).find('#login')[0]);
+ assert.ok(stub.calledOnce);
+ });
+
+ it('in case of nothing in state, should pass actual values to Actions.login()', function () {
+ var username = 'bob';
+ var password = 'smith';
+
+ loginForm = TestUtils.renderIntoDocument(
+ <Components.LoginForm
+ testBlankUsername={username}
+ testBlankPassword={password}
+ />, container);
+
+ TestUtils.Simulate.submit($(ReactDOM.findDOMNode(loginForm)).find('#login')[0]);
+ assert.ok(stub.calledOnce);
+
+ // confirm Actions.login() received the values that weren't in the DOM
+ assert.equal(stub.args[0][0], username);
+ assert.equal(stub.args[0][1], password);
+ });
+
+ });
+
+ describe('ChangePasswordForm', function () {
+ var container, changePasswordForm;
+
+ beforeEach(function () {
+ container = document.createElement('div');
+ changePasswordForm = TestUtils.renderIntoDocument(<Components.ChangePasswordForm />, container);
+ utils.restore(Actions.changePassword);
+ });
+
+ afterEach(function () {
+ ReactDOM.unmountComponentAtNode(container);
+ });
- it('should call action to update password confirm on field change', function () {
- var spy = sinon.spy(Actions, 'updateCreateAdminPassword');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(createAdminForm)).find('#password')[0], { target: { value: 'topnotch' }});
- assert.ok(spy.calledOnce);
- });
+ it('should call action to update password on field change', function () {
+ var spy = sinon.spy(Actions, 'updateChangePasswordField');
+ TestUtils.Simulate.change($(ReactDOM.findDOMNode(changePasswordForm)).find('#password')[0], { target: { value: 'bobsyouruncle' }});
+ assert.ok(spy.calledOnce);
});
- describe('CreateAdminSidebar', function () {
- var container, createAdminSidebar;
+ it('should call action to update password confirm on field change', function () {
+ var spy = sinon.spy(Actions, 'updateChangePasswordConfirmField');
+ TestUtils.Simulate.change($(ReactDOM.findDOMNode(changePasswordForm)).find('#password-confirm')[0], { target: { value: 'hotdiggity' }});
+ assert.ok(spy.calledOnce);
+ });
- beforeEach(function () {
- createAdminSidebarStore.reset();
- container = document.createElement('div');
- createAdminSidebar = TestUtils.renderIntoDocument(<Components.CreateAdminSidebar />, container);
- });
+ it('should call action to submit form', function () {
+ var stub = sinon.stub(Actions, 'changePassword', function () {});
+ TestUtils.Simulate.submit($(ReactDOM.findDOMNode(changePasswordForm)).find('#change-password')[0]);
+ assert.ok(stub.calledOnce);
+ });
+ });
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
- });
+ describe('CreateAdminForm', function () {
+ var container, createAdminForm;
- it('confirm the default selected nav item is the change pwd page', function () {
- assert.equal($(ReactDOM.findDOMNode(createAdminSidebar)).find('.active').find('a').attr('href'), '#changePassword');
- });
+ beforeEach(function () {
+ container = document.createElement('div');
+ createAdminForm = TestUtils.renderIntoDocument(<Components.CreateAdminForm loginAfter={false} />, container);
+ });
- it('confirm clicking a sidebar nav item selects it in the DOM', function () {
- TestUtils.Simulate.click($(ReactDOM.findDOMNode(createAdminSidebar)).find('li[data-page="addAdmin"]').find('a')[0]);
- assert.equal($(ReactDOM.findDOMNode(createAdminSidebar)).find('.active').find('a').attr('href'), '#addAdmin');
- });
+ afterEach(function () {
+ ReactDOM.unmountComponentAtNode(container);
});
+ it('should call action to update username on field change', function () {
+ var spy = sinon.spy(Actions, 'updateCreateAdminUsername');
+ TestUtils.Simulate.change($(ReactDOM.findDOMNode(createAdminForm)).find('#username')[0], { target: { value: 'catsmeow' }});
+ assert.ok(spy.calledOnce);
+ });
+
+ it('should call action to update password confirm on field change', function () {
+ var spy = sinon.spy(Actions, 'updateCreateAdminPassword');
+ TestUtils.Simulate.change($(ReactDOM.findDOMNode(createAdminForm)).find('#password')[0], { target: { value: 'topnotch' }});
+ assert.ok(spy.calledOnce);
+ });
+ });
+
+ describe('CreateAdminSidebar', function () {
+ var container, createAdminSidebar;
+
+ beforeEach(function () {
+ createAdminSidebarStore.reset();
+ container = document.createElement('div');
+ createAdminSidebar = TestUtils.renderIntoDocument(<Components.CreateAdminSidebar />, container);
+ });
+
+ afterEach(function () {
+ ReactDOM.unmountComponentAtNode(container);
+ });
+
+ it('confirm the default selected nav item is the change pwd page', function () {
+ assert.equal($(ReactDOM.findDOMNode(createAdminSidebar)).find('.active').find('a').attr('href'), '#changePassword');
+ });
+
+ it('confirm clicking a sidebar nav item selects it in the DOM', function () {
+ TestUtils.Simulate.click($(ReactDOM.findDOMNode(createAdminSidebar)).find('li[data-page="addAdmin"]').find('a')[0]);
+ assert.equal($(ReactDOM.findDOMNode(createAdminSidebar)).find('.active').find('a').attr('href'), '#addAdmin');
+ });
});
});