summaryrefslogtreecommitdiff
path: root/umClient.php
diff options
context:
space:
mode:
Diffstat (limited to 'umClient.php')
-rw-r--r--umClient.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/umClient.php b/umClient.php
new file mode 100644
index 0000000..c94ed94
--- /dev/null
+++ b/umClient.php
@@ -0,0 +1,40 @@
+<?php
+
+class umClient {
+ private $um_url = '';
+ private $cookiejar = '';
+
+ public function __construct($um_url, $cookiejar) {
+ $this->um_url = $um_url;
+ $this->cookiejar = $cookiejar;
+ }
+
+ public function get_userinfo($username, $password) {
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->um_url.'/auth');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiejar);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, array(
+ 'action'=>'login',
+ 'username'=>$username,
+ 'password'=>$password));
+ curl_exec($ch);
+ $auth_status=curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+
+ if ($auth_status!==200) {
+ // couldn't log in
+ return $auth_status;
+ }
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $this->um_url.'/users/'.$username.'.json');
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiejar);
+ curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiejar);
+ $json_str = curl_exec($ch);
+ $json_arr = json_decode($json_str, true);
+ return $json_arr[0];
+ }
+}