This commit is contained in:
Professional 2025-05-25 02:29:07 +07:00
parent 404091563a
commit 5a485de698
2 changed files with 41 additions and 14 deletions

View File

@ -23,6 +23,21 @@ const registerUser = async (req, res, next) => {
throw new Error('Пожалуйста, заполните все обязательные поля: имя, email, пароль и дату рождения.'); throw new Error('Пожалуйста, заполните все обязательные поля: имя, email, пароль и дату рождения.');
} }
// Проверка возраста (минимум 14 лет)
const birthDate = new Date(dateOfBirth);
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
if (age < 14) {
res.status(400);
throw new Error('Для регистрации необходим возраст не менее 14 лет.');
}
const normalizedEmail = email.toLowerCase(); const normalizedEmail = email.toLowerCase();
console.log('Нормализованный email для поиска:', normalizedEmail); console.log('Нормализованный email для поиска:', normalizedEmail);

View File

@ -52,15 +52,19 @@
<i class="bi-calendar"></i> <i class="bi-calendar"></i>
Дата рождения Дата рождения
</label> </label>
<input <div class="date-input-container">
type="date" <input
id="birthdate" type="date"
v-model="birthdate" id="birthdate"
required v-model="birthdate"
:disabled="loading" required
:max="maxDate" :disabled="loading"
class="date-input" :max="maxDate"
/> class="date-input"
ref="birthdateInput"
@click="openDatePicker"
/>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -136,11 +140,19 @@ const password = ref('');
const confirmPassword = ref(''); const confirmPassword = ref('');
const errorMessage = ref(''); const errorMessage = ref('');
const loading = ref(false); const loading = ref(false);
const birthdateInput = ref(null);
// Вычисляем максимальную дату (минимальный возраст 18 лет) // Функция для открытия календаря при клике на поле
const openDatePicker = () => {
if (birthdateInput.value && typeof birthdateInput.value.showPicker === 'function') {
birthdateInput.value.showPicker();
}
};
// Вычисляем максимальную дату (минимальный возраст 14 лет)
const maxDate = computed(() => { const maxDate = computed(() => {
const date = new Date(); const date = new Date();
date.setFullYear(date.getFullYear() - 18); date.setFullYear(date.getFullYear() - 14);
return date.toISOString().split('T')[0]; return date.toISOString().split('T')[0];
}); });
@ -191,7 +203,7 @@ const handleRegister = async () => {
return; return;
} }
// Проверяем возраст (минимум 18 лет) // Проверяем возраст (минимум 14 лет)
const birthDate = new Date(birthdate.value); const birthDate = new Date(birthdate.value);
const today = new Date(); const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear(); let age = today.getFullYear() - birthDate.getFullYear();
@ -201,8 +213,8 @@ const handleRegister = async () => {
age--; age--;
} }
if (age < 18) { if (age < 14) {
errorMessage.value = 'Вам должно быть не менее 18 лет для регистрации.'; errorMessage.value = 'Вам должно быть не менее 14 лет для регистрации.';
loading.value = false; loading.value = false;
return; return;
} }