2022-12-15 14:50:58 +00:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
require_once 'config.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
|
|
|
|
if (isset($_SESSION["username"]) && isset($_SESSION["admin"]))
|
|
|
|
{
|
|
|
|
$username = $_POST["username"];
|
|
|
|
$password = $_POST["password"];
|
|
|
|
$admin = $_POST["admin"];
|
|
|
|
|
|
|
|
$conn = dbConn();
|
|
|
|
$stmt = $conn->prepare("INSERT INTO Users (Users_username, Users_password, Users_admin) VALUES (:username, :password, :admin)");
|
|
|
|
$stmt->bindParam(":username", $username);
|
|
|
|
$stmt->bindParam(":password", $password);
|
|
|
|
$isAdmin = $admin ? 1 : 0;
|
|
|
|
$stmt->bindParam(":admin", $isAdmin);
|
|
|
|
$stmt->execute();
|
|
|
|
|
2022-12-16 12:19:38 +00:00
|
|
|
$logSQL = "INSERT INTO Logs (Logs_type, Users_username, Logs_date) VALUES (:type, :username, NOW())";
|
|
|
|
$logStmt = $conn->prepare($logSQL);
|
|
|
|
$type = !$admin ? "Add user" : "Add admin";
|
|
|
|
$logStmt->bindParam(":type", $type);
|
|
|
|
$logStmt->bindParam(":username", $_SESSION["username"]);
|
|
|
|
$logStmt->execute();
|
|
|
|
|
2022-12-15 14:50:58 +00:00
|
|
|
echo json_encode(array("message" => "ok", "admin" => $admin));
|
|
|
|
}
|
|
|
|
else if (isset($_SESSION["username"]) && !isset($_SESSION["admin"]))
|
|
|
|
{
|
|
|
|
echo json_encode(array("message" => "not logged in as admin"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
echo json_encode(array("message" => "Not logged in "));
|
|
|
|
}
|