Reflex/backend/utils/initAdmin.js
2025-05-25 23:11:02 +07:00

39 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const User = require('../models/User');
/**
* Инициализирует административный аккаунт в системе
* Аккаунт создается с логином admin и паролем admin124
* Этот аккаунт будет всегда активен
*/
const initAdminAccount = async () => {
try {
// Проверяем, существует ли уже админ
const adminExists = await User.findOne({ email: 'admin', isAdmin: true });
if (!adminExists) {
// Создаем админа, если не существует
const admin = new User({
name: 'Администратор',
email: 'admin',
password: 'admin124',
dateOfBirth: new Date('1990-01-01'), // Устанавливаем формальную дату рождения
gender: 'other',
isActive: true,
isAdmin: true,
location: {
city: 'Admin',
country: 'System'
}
});
await admin.save();
console.log('Административный аккаунт успешно создан');
} else {
console.log('Административный аккаунт уже существует');
}
} catch (error) {
console.error('Ошибка при инициализации админ-аккаунта:', error);
}
};
module.exports = initAdminAccount;