-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
50 lines (44 loc) · 1.15 KB
/
index.php
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
41
42
43
44
45
46
47
48
49
50
<?php
//header('Content-type: application/json');
include('openinviter.php');
function errorcheck($invite, $msg)
{
if ($invite->getInternalError()) {
throw new Exception($msg);
}
}
function get_contacts($u, $p)
{
$inviter = new OpenInviter();
$inviter->getPlugins();
$provider = $inviter->getPluginByDomain($u);
if (!$provider) {
throw new Exception('Invalid domain');
}
$inviter->startPlugin($provider);
errorcheck($inviter, 'Error initializing plugin');
$login_succeeded = $inviter->login($u, $p);
errorcheck($inviter, 'Login failed');
if (!$login_succeeded) {
throw new Exception('Login failed!');
}
$contacts = $inviter->getMyContacts();
errorcheck($inviter, 'Contacts could not be retrieved');
if ($contacts === false) {
throw new Exception('No contacts found');
}
return $contacts;
}
try {
$email = $_POST['email'];
$password = $_POST['password'];
if (!$email || !$password) {
throw new Exception('Missing credentials');
}
$contacts = get_contacts($email, $password);
echo json_encode(array($contacts, null));
}
catch (Exception $e) {
echo json_encode(array(null, $e->getMessage()));
}
?>