fleet/frontend/components/forms/ChangePasswordForm/validate.js
Mike Stone 638ec8a1f3 Modify user endpoints (#1023)
* Update admin API client

* updateAdmin redux action

* Changes UserManagementPage actions for update admin

* Enable user API client

* Enable user redux actions

* Change UserManagementPage to dispatch enable user actions

* Connect change password to API
2017-01-19 14:55:42 -05:00

33 lines
871 B
JavaScript

import { size } from 'lodash';
import validateEquality from 'components/forms/validators/validate_equality';
export default (formData) => {
const errors = {};
const {
old_password: oldPassword,
new_password: newPassword,
new_password_confirmation: newPasswordConfirmation,
} = formData;
if (!oldPassword) {
errors.old_password = 'Password must be present';
}
if (!newPassword) {
errors.new_password = 'New password must be present';
}
if (!newPasswordConfirmation) {
errors.new_password_confirmation = 'New password confirmation must be present';
}
if (newPassword && newPasswordConfirmation &&
!validateEquality(newPassword, newPasswordConfirmation)) {
errors.new_password_confirmation = 'New password confirmation does not match new password';
}
const valid = !size(errors);
return { valid, errors };
};