2021-04-12 13:32:25 +00:00
|
|
|
import { size } from "lodash";
|
|
|
|
import validateEquality from "components/forms/validators/validate_equality";
|
|
|
|
import validPassword from "components/forms/validators/valid_password";
|
2016-12-13 15:24:58 +00:00
|
|
|
|
|
|
|
export default (formData) => {
|
|
|
|
const errors = {};
|
|
|
|
const {
|
2017-01-19 19:55:42 +00:00
|
|
|
old_password: oldPassword,
|
2016-12-13 15:24:58 +00:00
|
|
|
new_password: newPassword,
|
|
|
|
new_password_confirmation: newPasswordConfirmation,
|
|
|
|
} = formData;
|
|
|
|
|
2017-02-07 14:29:48 +00:00
|
|
|
if (newPassword && newPasswordConfirmation && !validPassword(newPassword)) {
|
2021-06-15 13:51:04 +00:00
|
|
|
errors.new_password = "Password must meet the criteria below";
|
2017-02-07 14:29:48 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 19:55:42 +00:00
|
|
|
if (!oldPassword) {
|
2021-04-12 13:32:25 +00:00
|
|
|
errors.old_password = "Password must be present";
|
2016-12-13 15:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!newPassword) {
|
2021-04-12 13:32:25 +00:00
|
|
|
errors.new_password = "New password must be present";
|
2016-12-13 15:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!newPasswordConfirmation) {
|
2021-04-12 13:32:25 +00:00
|
|
|
errors.new_password_confirmation =
|
|
|
|
"New password confirmation must be present";
|
2016-12-13 15:24:58 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
if (
|
|
|
|
newPassword &&
|
|
|
|
newPasswordConfirmation &&
|
|
|
|
!validateEquality(newPassword, newPasswordConfirmation)
|
|
|
|
) {
|
|
|
|
errors.new_password_confirmation =
|
|
|
|
"New password confirmation does not match new password";
|
2016-12-13 15:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const valid = !size(errors);
|
|
|
|
|
|
|
|
return { valid, errors };
|
|
|
|
};
|