Initial commit
This commit is contained in:
29
backend/scripts/create-admin.js
Normal file
29
backend/scripts/create-admin.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const bcrypt = require('bcrypt');
|
||||
const pool = require('../src/config/database');
|
||||
|
||||
async function createAdmin() {
|
||||
const username = 'admin';
|
||||
const password = 'admin123'; // Измените после первого входа!
|
||||
const passwordHash = await bcrypt.hash(password, 10);
|
||||
|
||||
try {
|
||||
const result = await pool.query(`
|
||||
INSERT INTO users (username, password_hash, full_name, email, role, is_active)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
ON CONFLICT (username) DO UPDATE
|
||||
SET password_hash = $2
|
||||
RETURNING id, username, role
|
||||
`, [username, passwordHash, 'Главный администратор', 'admin@polotsk-transit.local', 'admin', true]);
|
||||
|
||||
console.log('✅ Мастер-аккаунт создан:', result.rows[0]);
|
||||
console.log('Username: admin');
|
||||
console.log('Password: admin123');
|
||||
console.log('⚠️ ОБЯЗАТЕЛЬНО смените пароль после первого входа!');
|
||||
} catch (error) {
|
||||
console.error('❌ Ошибка:', error);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
createAdmin();
|
||||
Reference in New Issue
Block a user