Github user garrensmith commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/833#discussion_r100529500
--- Diff: app/addons/auth/actions.js ---
@@ -10,148 +10,162 @@
// License for the specific language governing permissions and limitations
under
// the License.
import FauxtonAPI from "../../core/api";
-import ActionTypes from "./actiontypes";
+import { session } from "../../core/couchdb";
+import {
+ AUTH_CLEAR_CHANGE_PWD_FIELDS,
+ AUTH_UPDATE_CHANGE_PWD_FIELD,
+ AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD,
+ AUTH_CLEAR_CREATE_ADMIN_FIELDS,
+ AUTH_CREDS_VALID,
+ AUTH_CREDS_INVALID,
+ AUTH_UPDATE_CREATE_ADMIN_USERNAME_FIELD,
+ AUTH_UPDATE_CREATE_ADMIN_PWD_FIELD,
+ AUTH_SELECT_PAGE,
+ AUTH_SHOW_PASSWORD_MODAL,
+ AUTH_HIDE_PASSWORD_MODAL
+} 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;
- }
+const nodesStore = ClusterStore.nodesStore;
+function errorHandler({ message }) {
FauxtonAPI.addNotification({
- msg: msg,
- type: 'error'
+ msg: message,
+ type: "error"
});
};
-
-function login (username, password, urlBack) {
- var promise = FauxtonAPI.session.login(username, password);
-
- promise.then(() => {
- FauxtonAPI.addNotification({ msg: FauxtonAPI.session.messages.loggedIn
});
- if (urlBack) {
- return FauxtonAPI.navigate(urlBack);
- }
- FauxtonAPI.navigate('/');
- }, errorHandler);
+export function login(username, password, urlBack) {
+ return FauxtonAPI.session.login(username, password)
+ .then(() => {
+ FauxtonAPI.addNotification({ msg:
FauxtonAPI.session.messages.loggedIn });
+ if (urlBack && !urlBack.includes("login")) {
+ return FauxtonAPI.navigate(urlBack);
+ }
+ FauxtonAPI.navigate("/");
+ })
+ .catch(errorHandler);
}
-function changePassword (password, passwordConfirm) {
+export function changePassword(password, passwordConfirm) {
var nodes = nodesStore.getNodes();
- var promise = FauxtonAPI.session.changePassword(password,
passwordConfirm, nodes[0].node);
-
- promise.then(() => {
- FauxtonAPI.addNotification({ msg:
FauxtonAPI.session.messages.changePassword });
- FauxtonAPI.dispatch({ type: ActionTypes.AUTH_CLEAR_CHANGE_PWD_FIELDS
});
- }, errorHandler);
+ var promise = FauxtonAPI.session.changePassword(
+ password,
+ passwordConfirm,
+ nodes[0].node
+ );
+
+ promise.then(
+ () => {
+ FauxtonAPI.addNotification({
+ msg: FauxtonAPI.session.messages.changePassword
+ });
+ FauxtonAPI.dispatch({ type: AUTH_CLEAR_CHANGE_PWD_FIELDS });
+ },
+ errorHandler
+ );
}
-function updateChangePasswordField (value) {
+export function updateChangePasswordField(value) {
FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_UPDATE_CHANGE_PWD_FIELD,
+ type: AUTH_UPDATE_CHANGE_PWD_FIELD,
value: value
});
}
-function updateChangePasswordConfirmField (value) {
+export function updateChangePasswordConfirmField(value) {
FauxtonAPI.dispatch({
- type: ActionTypes.AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD,
+ type: AUTH_UPDATE_CHANGE_PWD_CONFIRM_FIELD,
value: value
});
}
-function createAdmin (username, password, loginAfter) {
+export function createAdmin(username, password, loginAfter) {
var nodes = nodesStore.getNodes();
- var promise = FauxtonAPI.session.createAdmin(username, password,
loginAfter, nodes[0].node);
-
- promise.then(() => {
- FauxtonAPI.addNotification({ msg:
FauxtonAPI.session.messages.adminCreated });
- if (loginAfter) {
- FauxtonAPI.navigate('/');
- } else {
- FauxtonAPI.dispatch({ type:
ActionTypes.AUTH_CLEAR_CREATE_ADMIN_FIELDS });
+ FauxtonAPI.session.createAdmin(
+ username,
+ password,
+ loginAfter,
+ nodes[0].node
+ )
+ .then(
+ () => {
+ FauxtonAPI.addNotification({
+ msg: FauxtonAPI.session.messages.adminCreated
+ });
+ if (loginAfter) {
+ FauxtonAPI.navigate("/");
+ } else {
+ FauxtonAPI.dispatch({ type: AUTH_CLEAR_CREATE_ADMIN_FIELDS });
+ }
+ },
+ (xhr, type, msg) => {
+ msg = xhr;
+ if (arguments.length === 3) {
+ msg = xhr.responseJSON.reason;
+ }
+ errorHandler(
+ FauxtonAPI.session.messages.adminCreationFailedPrefix + " " + msg
--- End diff --
Could you use the es2015 string interpolation:
` `${ FauxtonAPI.session.messages.adminCreationFailedPrefix} ${msg}` `
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---