mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 12:07:10 -04:00
Switch API to react to POST only.
This commit is contained in:
parent
3360e4d167
commit
af6c715a5b
3 changed files with 13 additions and 11 deletions
|
@ -16,7 +16,7 @@ class Api {
|
|||
public function apply() {
|
||||
|
||||
$action = Util::use_request_param("action");
|
||||
Util::json_fail(100, "unsupported request", !in_array($action, $this->actions));
|
||||
Util::json_fail(101, "unsupported action", !in_array($action, $this->actions));
|
||||
|
||||
$methodname = "on_${action}";
|
||||
$this->$methodname();
|
||||
|
@ -102,10 +102,6 @@ class Api {
|
|||
$response["all_items"] = $this->app->get_all_items();
|
||||
}
|
||||
|
||||
if (AS_ADMIN && count($_REQUEST)) {
|
||||
$response["unused"] = $_REQUEST;
|
||||
}
|
||||
|
||||
Util::json_exit($response);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class Bootstrap {
|
|||
Bootstrap::setup();
|
||||
|
||||
$app = new App();
|
||||
if (Util::has_request_param("action")) {
|
||||
if (Util::is_post_request()) {
|
||||
$api = new Api($app);
|
||||
$api->apply();
|
||||
} else {
|
||||
|
|
|
@ -29,21 +29,27 @@ class Util {
|
|||
}
|
||||
|
||||
|
||||
public static function is_post_request() {
|
||||
|
||||
return (strtolower($_SERVER['REQUEST_METHOD']) === 'post');
|
||||
}
|
||||
|
||||
|
||||
public static function has_request_param($key) {
|
||||
|
||||
return array_key_exists($key, $_REQUEST);
|
||||
return array_key_exists($key, $_POST);
|
||||
}
|
||||
|
||||
|
||||
public static function use_request_param($key, $default = null) {
|
||||
|
||||
if (!array_key_exists($key, $_REQUEST)) {
|
||||
Util::json_fail(101, "parameter '$key' is missing", $default === null);
|
||||
if (!array_key_exists($key, $_POST)) {
|
||||
Util::json_fail(100, "parameter '$key' is missing", $default === null);
|
||||
return $default;
|
||||
}
|
||||
|
||||
$value = $_REQUEST[$key];
|
||||
unset($_REQUEST[$key]);
|
||||
$value = $_POST[$key];
|
||||
unset($_POST[$key]);
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue