summaryrefslogtreecommitdiff
path: root/umClient.php
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-08-04 20:06:44 -0700
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-08-04 20:06:44 -0700
commitb0782a625d50c6fce4da50d5c604f5cc4f128b43 (patch)
tree5a1570d3ef160f2858e7feb8625d7dfaddecf522 /umClient.php
parentcc63226762c39c22340b830a4daea6d4b3a55e21 (diff)
initial fork of simple-ldap-pluginHEADsimple-um-login
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];
+ }
+}