summaryrefslogtreecommitdiff
path: root/pages/api/rename.php
diff options
context:
space:
mode:
Diffstat (limited to 'pages/api/rename.php')
-rw-r--r--pages/api/rename.php26
1 files changed, 23 insertions, 3 deletions
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