adding auth
This commit is contained in:
@@ -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
|
||||
)
|
||||
");
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user