Fiksa header pssord og la til minkadavertid

This commit is contained in:
Trygve 2025-10-31 11:59:38 +01:00
parent 2aff55b50d
commit 5f377cf811
4 changed files with 42 additions and 29 deletions

View File

@ -57,9 +57,9 @@ include("api/statistics.php");
</form>
<div id="runner" class="profile-card"></div>
<button hx-get="/api/email.php" hx-target="#emails" hx-headers='js:{"password": localStorage.getItem("passord")}'>hent alle eposter</button>
<button hx-get="/api/email.php?course=Kadaverløpet" hx-target="#emails" hx-headers='js:{"password": localStorage.getItem("passord")}'>Hent bare eposter for fullkadavern</button>
<button hx-get="/api/email.php?course=Minikadaver'n" hx-target="#emails" hx-headers='js:{"password": localStorage.getItem("passord")}'>Hent bare eposter for minikadaver'n</button>
<button hx-get="/api/email.php" hx-target="#emails" hx-headers='js:{"Password": localStorage.getItem("passord")}'>hent alle eposter</button>
<button hx-get="/api/email.php?course=Kadaverløpet" hx-target="#emails" hx-headers='js:{"Password": localStorage.getItem("passord")}'>Hent bare eposter for fullkadavern</button>
<button hx-get="/api/email.php?course=Minikadaver'n" hx-target="#emails" hx-headers='js:{"Password": localStorage.getItem("passord")}'>Hent bare eposter for minikadaver'n</button>
<div class="flash default">
<output id="emails"></output>
</div>

View File

@ -22,8 +22,11 @@ include("$documentRoot/data/hash.php");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "POST") {
$start_time = $_POST['start_time'];
$start_time_mini = $_POST['mini_time'];
$password = $_POST['Password'];
$password = getallheaders()['Password'];
$password = $_POST['password'];
$new_time = DateTime::createFromFormat(DateTime::ISO8601, $start_time. "+01");
if (!password_verify($password, $hash)) {
@ -35,13 +38,30 @@ if ($method == "POST") {
$file = "$documentRoot/data/config.ini";
$config["start_date"] = $start_time . "+01";
$config["start_date_mini"] = $start_time_mini . "+01";
write_ini_file($config, $file);
header("HX-Replace-Url: false");
echo("Starttida er oppdatert til: $start_time");
echo("Starttida er oppdatert til: $start_time for Kadaver'n <br> $start_time_mini for Minikadaer'n");
}
}
elseif ($method == "GET"){
print($config["start_date"]);
$start_kadaver = explode("+", $config["start_date"])[0];
$start_mini = explode("+", $config["start_date_mini"])[0];
$response = "
<form action='/api/config.php' method='POST' hx-boost='true' hx-target='#updated' hx-swap='show:none' hx-headers='js:{\"Password\": localStorage.getItem(\"passord\")}'>
<label>
Starttid Kadaverløpet
<input type='datetime-local' id='start_time' name='start_time' step='1' value='$start_kadaver'>
</label>
<label>
Starttid Minikadaver'n
<input type='datetime-local' id='mini_time' name='mini_time' step='1' value='$start_mini'>
</label>
<button type='submit'>Oppdater</button>
</form>
<div id='updated'></div>
";
echo($response);
}

View File

@ -6,10 +6,11 @@ $method = $_SERVER['REQUEST_METHOD'];
if ($method == "GET") {
parse_str($_SERVER['QUERY_STRING'], $query);
$course = $query['course'];
$password = getallheaders()['password'];
$password = getallheaders()['Password'];
print_r(getallheaders());
if (!password_verify($password, $hash)) {
http_response_code(response_code: 401);
}
} else {
$runners = read_runners_from_csv();
$emails = "";
for ($i = 0; $i < count($runners); $i++) {
@ -22,4 +23,5 @@ if ($method == "GET") {
}
}
echo($emails);
}
}

View File

@ -29,16 +29,7 @@
</nav>
<h2>Sett dato og tid startskuddet gikk:</h2>
<form action="/api/config.php" method="POST" hx-boost="true" hx-target="#updated" hx-swap="show:none">
<input style="display: none;" type="text" id="password" name="password" required>
<label>
Dato og tid
<input type="datetime-local" id="start_time" name="start_time" step="1">
</label>
<button type="submit">Oppdater</button>
</form>
<div id="updated"></div>
</div>
<div hx-get="/api/config.php" hx-swap="outerHTML" hx-trigger="load"></div>
<script>
function log_out(){
localStorage.removeItem("navn");