add reset password

This commit is contained in:
smanylov
2026-02-02 15:00:56 +07:00
parent 19e807a7f6
commit 7789f19055
8 changed files with 457 additions and 95 deletions
+53 -69
View File
@@ -163,79 +163,63 @@ export function createValidationSchema(config: ValidationConfig, accountType?: '
schema.password = passwordSchema;
}
// companyName (опциональное поле), надо будет удалить потом
/* if (config.companyName) {
let companySchema = z.string();
// Если поле опциональное, добавляем .optional().nullable()
if (config.companyName.optional?.value) {
companySchema = companySchema
.optional()
.nullable()
.transform((val) => (val === null || val === undefined ? '' : val))
.refine(
(value) => {
// Для пустого значения пропускаем проверки
if (!value || value.trim().length === 0) return true;
// Проверка минимальной длины
const minLength = config.companyName?.minSize?.value || 2;
return value.trim().length >= minLength;
},
{
message: config.companyName.minSize?.message || 'register-error-company-name-min'
}
) as unknown as z.ZodString;
} else {
// Если поле обязательное
if (config.companyName.minSize) {
companySchema = companySchema.min(config.companyName.minSize.value, {
error: config.companyName.minSize.message
});
}
}
// Максимальная длина (применяется всегда)
if (config.companyName.maxSize) {
companySchema = companySchema.refine(
(value) => {
if (config.companyName?.optional?.value && (!value || value.trim().length === 0)) {
return true;
}
const maxLength = config.companyName?.maxSize?.value || 200;
return (value || '').trim().length <= maxLength;
},
{
message: config.companyName.maxSize.message
}
);
}
// Допустимые символы
if (config.companyName.allowedSymbols?.value) {
companySchema = companySchema.refine(
(value) => {
if (config.companyName?.optional?.value && (!value || value.trim().length === 0)) {
return true;
}
const regex = new RegExp(config.companyName.allowedSymbols!.value);
return regex.test(value || '');
},
{
message: config.companyName.allowedSymbols.message
}
);
}
companySchema = companySchema.transform((val) => val?.trim() || '') as unknown as z.ZodString;
schema.companyName = companySchema;
} */
// Дополнительные поля для формы регистрации
schema.confirm_password = z.string();
schema.agree = z.string().min(2, { error: 'register-error-agree' });
return z
.object(schema)
.refine((data) => data.password === data.confirm_password, {
message: 'repeat-password',
path: ['confirm_password'],
});
}
export function createValidationSchemaForPssword(config: ValidationConfig) {
const schema: Record<string, any> = {};
// password
if (config.password) {
let passwordSchema = z
.string()
.min(config.password.minSize?.value || 8, {
error: config.password.minSize?.message || 'register-error-password-symbols'
})
.max(config.password.maxSize?.value || 124, {
error: config.password.maxSize?.message || 'register-error-max-password'
})
.trim();
// Проверка допустимых символов
if (config.password.allowedSymbols?.value) {
passwordSchema = passwordSchema.regex(
new RegExp(config.password.allowedSymbols.value),
{ message: config.password.allowedSymbols.message }
);
}
// Проверка наличия цифры
if (config.password.requiredDigit?.value) {
passwordSchema = passwordSchema.regex(
/[0-9]/,
{ message: config.password.requiredDigit.message }
);
}
// Проверка наличия буквы
if (config.password.requiredLetter?.value) {
passwordSchema = passwordSchema.regex(
/[a-zA-Zа-яёА-ЯЁ]/,
{ message: config.password.requiredLetter.message }
);
}
schema.password = passwordSchema;
}
// Дополнительные поля для формы регистрации
schema.confirm_password = z.string();
return z
.object(schema)
.refine((data) => data.password === data.confirm_password, {