61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
|
<?php
|
||
|
include('openinviter/openinviter.php');
|
||
|
$inviter = new OpenInviter();
|
||
|
$oi_services = $inviter->getPlugins();
|
||
|
|
||
|
if(isset($_POST['step']) && $_POST['step'] == 'get_contacts') {
|
||
|
if(empty($_POST['login'])) {
|
||
|
echo '{ "errors": "Login missing" }';
|
||
|
exit;
|
||
|
}
|
||
|
if(empty($_POST['password'])) {
|
||
|
echo '{ "errors": "Password missing" }';
|
||
|
exit;
|
||
|
}
|
||
|
if(empty($_POST['provider_box'])) {
|
||
|
echo '{ "errors": "Provider missing" }';
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$inviter->startPlugin($_POST['provider_box']);
|
||
|
|
||
|
$internal = $inviter->getInternalError();
|
||
|
if($internal) {
|
||
|
echo '{ "errors": "'.addslashes($internal).'" }';
|
||
|
exit;
|
||
|
} elseif(!$inviter->login($_POST['login'], $_POST['password'])) {
|
||
|
$internal = $inviter->getInternalError();
|
||
|
echo ($internal?'{ "errors": "'.addslashes($internal).'" }':'{ "errors": "Login failed. Please check the email and password you have provided and try again later" }');
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
$contacts = $inviter->getMyContacts();
|
||
|
if($contacts === FALSE) {
|
||
|
echo '{ "errors": "Unable to get contacts" }';
|
||
|
exit;
|
||
|
} else {
|
||
|
$result = array("errors" => false, "contacts" => array());
|
||
|
$types = array(
|
||
|
'email' => array(
|
||
|
'gmail',
|
||
|
),
|
||
|
'text' => array(
|
||
|
'facebook',
|
||
|
),
|
||
|
);
|
||
|
if(in_array($_POST['provider_box'], $types['email'])) {
|
||
|
$result['type'] = 'email';
|
||
|
} else {
|
||
|
$result['type'] = 'text';
|
||
|
}
|
||
|
foreach($contacts as $mail => $name) {
|
||
|
$result['contacts'][$mail] = $name;
|
||
|
}
|
||
|
echo json_encode($result);
|
||
|
exit;
|
||
|
}
|
||
|
}
|
||
|
echo '{ "errors": "Wrong request" }';
|
||
|
exit;
|
||
|
?>
|