adding auth

This commit is contained in:
2026-05-06 11:56:38 +02:00
parent 1de68361a9
commit 86f3d13629
8 changed files with 431 additions and 59 deletions
+7
View File
@@ -83,5 +83,12 @@ class Database
PRIMARY KEY (rule_id, window_start)
)
");
$this->pdo->exec("
CREATE TABLE IF NOT EXISTS config (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
)
");
}
}
+22
View File
@@ -145,6 +145,28 @@ class Repository
)->fetchAll();
}
// --- Config ---
public function getAllowedUserTokens(): array
{
$stmt = $this->db->pdo()->prepare("SELECT value FROM config WHERE key = ?");
$stmt->execute(['allowed_user_tokens']);
$row = $stmt->fetch();
if (!$row || empty($row['value'])) {
return [];
}
return json_decode($row['value'], true) ?? [];
}
public function setAllowedUserTokens(array $tokens): void
{
$stmt = $this->db->pdo()->prepare(
"INSERT INTO config (key, value) VALUES (?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value"
);
$stmt->execute(['allowed_user_tokens', json_encode(array_values($tokens))]);
}
// --- Rate Limiting ---
public function checkRateLimit(int $ruleId, int $windowSeconds): bool