1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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];
}
}
|