summaryrefslogtreecommitdiff
path: root/pages/api
diff options
context:
space:
mode:
authorRaindropsSys <contact@minteck.org>2023-05-16 22:17:15 +0200
committerRaindropsSys <contact@minteck.org>2023-05-16 22:17:15 +0200
commit98a84f3aa735f31b08e807c8a4f0549742cbd1b0 (patch)
tree9a510d41197d6af646f1ee0bdbf261437211f1bc /pages/api
parent60f7da42c41b35b44fa397397a5e4bccd6039d45 (diff)
downloadpluralconnect-98a84f3aa735f31b08e807c8a4f0549742cbd1b0.tar.gz
pluralconnect-98a84f3aa735f31b08e807c8a4f0549742cbd1b0.tar.bz2
pluralconnect-98a84f3aa735f31b08e807c8a4f0549742cbd1b0.zip
Updated 8 files (automated)
Diffstat (limited to 'pages/api')
-rw-r--r--pages/api/money/account.php2
-rw-r--r--pages/api/money/accounts.php4
-rw-r--r--pages/api/rename.php26
-rw-r--r--pages/api/session.php5
4 files changed, 29 insertions, 8 deletions
diff --git a/pages/api/money/account.php b/pages/api/money/account.php
index 6620733..1801b28 100644
--- a/pages/api/money/account.php
+++ b/pages/api/money/account.php
@@ -29,7 +29,7 @@ foreach ($accounts as $account) {
$acc["total"] = round(calculateFullAmount($account, true), 2);
$acc["interests"] = $account["interests"];
$acc["max"] = $account["max"];
- $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null;
+ $acc["used_percentage"] = isset($account["max"]) ? round((calculateFullAmount($account, true) / $account["max"]) * 100, 2) : null;
$acc["transactions"] = [];
foreach ($account["transactions"] as $index => $transaction) {
diff --git a/pages/api/money/accounts.php b/pages/api/money/accounts.php
index 22d8c77..9f85323 100644
--- a/pages/api/money/accounts.php
+++ b/pages/api/money/accounts.php
@@ -58,7 +58,7 @@ foreach ($accounts as $index => $account) {
$acc["total"] = round(calculateFullAmount($account, true), 2);
$acc["interests"] = $account["interests"];
$acc["max"] = $account["max"];
- $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null;
+ $acc["used_percentage"] = isset($account["max"]) ? round((calculateFullAmount($account, true) / $account["max"]) * 100, 2) : null;
$obj["users"]["cloudburst"]["accounts"][] = $acc;
}
@@ -84,7 +84,7 @@ foreach ($accounts as $index => $account) {
$acc["total"] = round(calculateFullAmount($account, true), 2);
$acc["interests"] = $account["interests"];
$acc["max"] = $account["max"];
- $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null;
+ $acc["used_percentage"] = isset($account["max"]) ? round((calculateFullAmount($account, true) / $account["max"]) * 100, 2) : null;
$acc["transactions"] = null;
$obj["users"]["raindrops"]["accounts"][] = $acc;
diff --git a/pages/api/rename.php b/pages/api/rename.php
index d450557..abec81e 100644
--- a/pages/api/rename.php
+++ b/pages/api/rename.php
@@ -10,8 +10,28 @@ if (!$isLoggedIn || $isLowerLoggedIn) {
die();
}
-$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN'])), true);
+$obj = [
+ "success" => true
+];
-$data["name"] = $_GET["name"] ?? $data["name"];
+global $token;
+$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token)), true);
-file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN']), json_encode($data)); \ No newline at end of file
+$data["name"] = $_POST["name"] ?? $_GET["name"] ?? $data["name"];
+$obj["pre_name"] = $data["name"];
+
+$request_raw = file_get_contents('php://input');
+$json_object = json_decode($request_raw, true);
+
+if (json_last_error() === JSON_ERROR_NONE) {
+ $obj["json_error"] = [ json_last_error(), json_last_error_msg() ];
+ if (isset($json_object["name"])) {
+ $data["name"] = $json_object["name"];
+ $obj["json_name"] = $json_object["name"];
+ }
+}
+
+$obj["new_name"] = $data["name"];
+
+file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token), json_encode($data));
+die(json_encode($obj)); \ No newline at end of file
diff --git a/pages/api/session.php b/pages/api/session.php
index f91288e..53e1845 100644
--- a/pages/api/session.php
+++ b/pages/api/session.php
@@ -14,11 +14,12 @@ if (!$isLoggedIn || $isLowerLoggedIn) {
], JSON_PRETTY_PRINT));
}
-$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $_COOKIE['PEH2_SESSION_TOKEN'])), true);
+global $token;
+$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/tokens/" . str_replace("/", "", $token)), true);
die(json_encode([
"name" => $data["name"],
"created" => date('c', $data["created"]),
"last_seen" => date('c', $data["last"]),
- "seen_at" => array_keys($data["addresses"])
+ "seen_at" => array_keys($data["addresses"] ?? [])
], JSON_PRETTY_PRINT)); \ No newline at end of file