aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/api.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/api.php')
-rw-r--r--engine/lib/api.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/engine/lib/api.php b/engine/lib/api.php
index ac4e5edbd..04a1a971f 100644
--- a/engine/lib/api.php
+++ b/engine/lib/api.php
@@ -681,6 +681,26 @@
}
/**
+ * Generate a new API user for a site, returning a new keypair on success.
+ *
+ * @param int $site_guid The GUID of the site.
+ */
+ function create_api_user($site_guid)
+ {
+ global $CONFIG;
+
+ $site_guid = (int)$site_guid;
+
+ $public = sha1(rand().$site_guid.microtime());
+ $secret = sha1(rand().$site_guid.microtime().$public);
+
+ if (insert_data("INSERT into {$CONFIG->dbprefix}api_users (site_guid, api_key, secret) values ($site_guid, '$public', '$private')"))
+ return get_api_user($site_guid, $public);
+
+ return false;
+ }
+
+ /**
* This function looks at the super-global variable $_SERVER and extracts the various
* header variables needed to pass to the validation functions after performing basic validation.
*