Enhance API functionality: add token generation methods, implement entry management, and improve setup process with settings storage
This commit is contained in:
1 parent
8ef5f7a941
commit
9316818753
9 files changed
+248
-25
No files matched your search
+24
-4
@@ -28,7 +28,7 @@ class gbAPI {
|
||||
return parse_ini_file(APP_PATH . ".env");
|
||||
}
|
||||
|
||||
function generateToken($username) {
|
||||
function generateCookieToken($username) {
|
||||
$config = $this->getConfig();
|
||||
|
||||
// Generate Token
|
||||
@@ -37,7 +37,21 @@ class gbAPI {
|
||||
"auth" => true
|
||||
];
|
||||
$string = json_encode($payload);
|
||||
$secret = $config["TOKEN_SIGNATURE"];
|
||||
$secret = $config["COOKIE_TOKEN_SIGNATURE"];
|
||||
|
||||
return hash_hmac("sha256", $string, $secret);
|
||||
}
|
||||
|
||||
function generateAPIToken($username) {
|
||||
$config = $this->getConfig();
|
||||
|
||||
// Generate Token
|
||||
$payload = [
|
||||
"user" => $username,
|
||||
"auth" => true
|
||||
];
|
||||
$string = json_encode($payload);
|
||||
$secret = $config["API_TOKEN_SIGNATURE"];
|
||||
|
||||
return hash_hmac("sha256", $string, $secret);
|
||||
}
|
||||
@@ -83,9 +97,11 @@ class gbAPI {
|
||||
}
|
||||
|
||||
function dbCommand($command, $expectResult, $stmtArgsRequired = false, $stmtArgs = []) {
|
||||
$db_path = APP_PATH . "database.db";
|
||||
$config = $this->getConfig();
|
||||
$db_name = $config["DB_NAME"];
|
||||
$db_path = APP_PATH . $db_name;
|
||||
|
||||
$db = new PDO("sqlite: " . $db_path);
|
||||
$db = new PDO("sqlite:" . $db_path);
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$stmt = $db->prepare($command);
|
||||
@@ -97,4 +113,8 @@ class gbAPI {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
function getSetting() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user