fixes for internal mxisd endpoints

This commit is contained in:
2018-03-08 13:20:26 +01:00
parent bce1d01b6d
commit d2b5cfbb5e
4 changed files with 20 additions and 9 deletions

View File

@@ -289,7 +289,7 @@ class mxDatabase
. " localpart LIKE '%" . $term . "%';"; . " localpart LIKE '%" . $term . "%';";
foreach ($this->db->query($sql) as $row) { foreach ($this->db->query($sql) as $row) {
array_push($result, [ array_push($result, [
"display_name" => $first_name . " " . $last_name, "display_name" => $row["first_name"] . " " . $row["last_name"],
"user_id" => $row["localpart"], "user_id" => $row["localpart"],
]); ]);
} }
@@ -309,7 +309,7 @@ class mxDatabase
. " email = '" . $term . "';"; . " email = '" . $term . "';";
foreach ($this->db->query($sql) as $row) { foreach ($this->db->query($sql) as $row) {
array_push($result, [ array_push($result, [
"display_name" => $first_name . " " . $last_name, "display_name" => $row["first_name"] . " " . $row["last_name"],
"user_id" => $row["localpart"], "user_id" => $row["localpart"],
]); ]);
} }
@@ -319,6 +319,10 @@ class mxDatabase
} }
if (!isset($mx_db)) { if (!isset($mx_db)) {
$mx_db = new mxDatabase($config["databaseURI"], $config["databaseUser"], $config["databasePass"]); if (isset($config["databaseUser"]) && isset($config["databasePass"])) {
$mx_db = new mxDatabase($config["databaseURI"], $config["databaseUser"], $config["databasePass"]);
} else {
$mx_db = new mxDatabase($config["databaseURI"]);
}
} }
?> ?>

View File

@@ -8,8 +8,11 @@ $response=[
try { try {
$inputJSON = file_get_contents('php://input'); $inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); $input = json_decode($inputJSON, TRUE);
if (empty($input)) {
throw new Exception('no valid json as input present');
}
if (!isset($input["by"])) { if (!isset($input["by"])) {
throw new Exception('"id" is not defined'); throw new Exception('"by" is not defined');
} }
if (!isset($input["search_term"])) { if (!isset($input["search_term"])) {
throw new Exception('"search_term" is not defined'); throw new Exception('"search_term" is not defined');
@@ -30,4 +33,4 @@ try {
$response["error"] = $e->getMessage(); $response["error"] = $e->getMessage();
} }
print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
?> ?>

View File

@@ -22,7 +22,7 @@ try {
$res2 = array(); $res2 = array();
switch ($lookup["medium"]) { switch ($lookup["medium"]) {
case "email": case "email":
$res2 = $mx_db->searchUserByEmail($input["lookup"]["address"]); $res2 = $mx_db->searchUserByEmail($lookup["address"]);
if (!empty($res2)) { if (!empty($res2)) {
array_push($response["lookup"], [ array_push($response["lookup"], [
"medium" => $lookup["medium"], "medium" => $lookup["medium"],
@@ -34,6 +34,7 @@ try {
] ]
); );
} }
break;
case "msisdn": case "msisdn":
error_log("sb requested a bulk lookup for msisdn"); error_log("sb requested a bulk lookup for msisdn");
break; break;
@@ -46,4 +47,4 @@ try {
$response["error"] = $e->getMessage(); $response["error"] = $e->getMessage();
} }
print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
?> ?>

View File

@@ -1,9 +1,12 @@
<?php <?php
require_once("../database.php"); require_once("../database.php");
$response = array(); $response = new stdClass;
try { try {
$inputJSON = file_get_contents('php://input'); $inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); $input = json_decode($inputJSON, TRUE);
if (empty($input)) {
throw new Exception('no valid json as input present');
}
if (!isset($input["lookup"])) { if (!isset($input["lookup"])) {
throw new Exception('"lookup" is not defined'); throw new Exception('"lookup" is not defined');
} }
@@ -40,4 +43,4 @@ try {
$response["error"] = $e->getMessage(); $response["error"] = $e->getMessage();
} }
print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
?> ?>