mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 09:18:59 +00:00
0f244140cc
- Add the `hint` that is used on the _Set up_ page to the _Change password_ form and _Reset password_ form - Add a consistent error message when a password fails to meet the criteria. Using the phrase "criteria below" because all pages render the above `hint`
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import { size } from "lodash";
|
|
import validateEquality from "components/forms/validators/validate_equality";
|
|
import validPassword from "components/forms/validators/valid_password";
|
|
|
|
export default (formData) => {
|
|
const errors = {};
|
|
const {
|
|
old_password: oldPassword,
|
|
new_password: newPassword,
|
|
new_password_confirmation: newPasswordConfirmation,
|
|
} = formData;
|
|
|
|
if (newPassword && newPasswordConfirmation && !validPassword(newPassword)) {
|
|
errors.new_password = "Password must meet the criteria below";
|
|
}
|
|
|
|
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 };
|
|
};
|