Fixed some small styling issues and validation schema

This commit is contained in:
Daniel Cojocea committed 2024-06-27 13:35:12 -04:00
1 parent 25355c69c2
commit 3b88ea01d0
3 files changed
+40 -44

No files matched your search

+35 -37
View File
@@ -82,43 +82,41 @@ const editProfileValidation = joi.object({
}),
});
const passwordSchema = joi
.string()
.trim()
.min(8)
.messages({
"string.empty": "*Password is required.",
"string.min": "*Password must be at least 8 characters long.",
})
.custom((value, helpers) => {
if (!/[A-Z]/.test(value)) {
return helpers.message(
"*Password must contain at least one uppercase letter."
);
}
if (!/[a-z]/.test(value)) {
return helpers.message(
"*Password must contain at least one lowercase letter."
);
}
if (!/\d/.test(value)) {
return helpers.message("*Password must contain at least one number.");
}
if (!/[!@#$%^&*]/.test(value)) {
return helpers.message(
"*Password must contain at least one special character."
);
}
return value;
});
const editPasswordValidation = joi.object({
// TBD - validation for current password ?
password : joi
.string().trim()
.messages({
"string.empty": "*Current password is required.",
}),
newpassword: joi
.string()
.trim()
.min(8)
.messages({
"string.empty": "*Password is required.",
"string.min": "*Password must be at least 8 characters long.",
})
.custom((value, helpers) => {
if (!/[A-Z]/.test(value)) {
return helpers.message(
"*Password must contain at least one uppercase letter."
);
}
if (!/[a-z]/.test(value)) {
return helpers.message(
"*Password must contain at least one lowercase letter."
);
}
if (!/\d/.test(value)) {
return helpers.message("*Password must contain at least one number.");
}
if (!/[!@#$%^&*]/.test(value)) {
return helpers.message(
"*Password must contain at least one special character."
);
}
return value;
}),
password: passwordSchema,
newpassword: passwordSchema,
confirm: joi
.string()
.trim()
@@ -126,8 +124,8 @@ const editPasswordValidation = joi.object({
"string.empty": "*Password confirmation is required.",
})
.custom((value, helpers) => {
const { password } = helpers.prefs.context;
if (value !== password) {
const { newpassword } = helpers.prefs.context;
if (value !== newpassword) {
return helpers.message("*Passwords do not match.");
}
return value;