From b0782a625d50c6fce4da50d5c604f5cc4f128b43 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 4 Aug 2012 20:06:44 -0700 Subject: initial fork of simple-ldap-plugin --- umClient.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 umClient.php (limited to 'umClient.php') diff --git a/umClient.php b/umClient.php new file mode 100644 index 0000000..c94ed94 --- /dev/null +++ b/umClient.php @@ -0,0 +1,40 @@ +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]; + } +} -- cgit v1.2.3