mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
* add prettier and have it format all js code except website: : * trying running prettier check in CI * fix runs on in CI * change CI job name * fix prettier erros and fix CI
43 lines
1.2 KiB
JavaScript
43 lines
1.2 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 be at least 7 characters and contain at least 1 letter, 1 number, and 1 symbol";
|
|
}
|
|
|
|
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 };
|
|
};
|