<?php
// /esp32/dashboard/scripts/create_team_user.php
// Disclaimer: This example code is part of a research prototype.
// It is provided “as is”, without any warranty of any kind.
// Please review, adapt, and test carefully before using it in production.
// Helper script to create a regular team user (or additional admins).
// Run this from the command line (php create_team_user.php).

// Database connection for this helper script.
// TODO: Replace the placeholders below with your own database configuration.
$dsn  = 'mysql:host=YOUR_DB_HOST_HERE;dbname=YOUR_DB_NAME_HERE;charset=utf8mb4';
$user = 'YOUR_DB_USER_HERE';
$pass = 'YOUR_DB_PASSWORD_HERE';

$options = [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];

try {
    $pdo = new PDO($dsn, $user, $pass, $options);

    // TODO: Set the credentials and role for the new user.
    $email    = 'user@example.org';
    $password = 'change-me';
    $role     = 'user'; // or 'admin' if you want to grant admin rights

    $hash = password_hash($password, PASSWORD_DEFAULT);

    $stmt = $pdo->prepare('INSERT INTO users (email, password_hash, role) VALUES (?, ?, ?)');
    $stmt->execute([$email, $hash, $role]);

    echo "✅ User created: {$email} (role: {$role})
";
} catch (Exception $e) {
    echo "❌ Error: " . $e->getMessage() . "
";
}
