30 lines
958 B
PHP
30 lines
958 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Add a default admin user if one doesn't exist
|
|
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = 'admin'");
|
|
$stmt->execute();
|
|
if ($stmt->fetch()) {
|
|
echo "Admin user already exists.\n";
|
|
} else {
|
|
$username = 'admin';
|
|
$password = 'password'; // You should change this!
|
|
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
|
|
$role = 'super_admin';
|
|
|
|
$stmt = $pdo->prepare("INSERT INTO users (username, password, role) VALUES (:username, :password, :role)");
|
|
$stmt->bindParam(':username', $username);
|
|
$stmt->bindParam(':password', $hashed_password);
|
|
$stmt->bindParam(':role', $role);
|
|
$stmt->execute();
|
|
echo "Default admin user created with username 'admin' and password 'password'.\n";
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
die("DB ERROR: " . $e->getMessage());
|
|
}
|
|
|