diff --git a/backend/controllers/authController.js b/backend/controllers/authController.js index 14410e2..4dc4ed6 100644 --- a/backend/controllers/authController.js +++ b/backend/controllers/authController.js @@ -23,6 +23,21 @@ const registerUser = async (req, res, next) => { 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(); console.log('Нормализованный email для поиска:', normalizedEmail); diff --git a/src/views/RegisterView.vue b/src/views/RegisterView.vue index 90a5662..40d2e3b 100644 --- a/src/views/RegisterView.vue +++ b/src/views/RegisterView.vue @@ -52,15 +52,19 @@ Дата рождения - +
+ +
@@ -136,11 +140,19 @@ const password = ref(''); const confirmPassword = ref(''); const errorMessage = ref(''); 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 date = new Date(); - date.setFullYear(date.getFullYear() - 18); + date.setFullYear(date.getFullYear() - 14); return date.toISOString().split('T')[0]; }); @@ -191,7 +203,7 @@ const handleRegister = async () => { return; } - // Проверяем возраст (минимум 18 лет) + // Проверяем возраст (минимум 14 лет) const birthDate = new Date(birthdate.value); const today = new Date(); let age = today.getFullYear() - birthDate.getFullYear(); @@ -201,8 +213,8 @@ const handleRegister = async () => { age--; } - if (age < 18) { - errorMessage.value = 'Вам должно быть не менее 18 лет для регистрации.'; + if (age < 14) { + errorMessage.value = 'Вам должно быть не менее 14 лет для регистрации.'; loading.value = false; return; }