WIP: implement missing endpoints for mxisd
This commit is contained in:
40
database.php
40
database.php
@@ -276,6 +276,46 @@ class mxDatabase
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function searchUserByName($search_term) {
|
||||
$term = filter_var($search_term, FILTER_SANITIZE_STRING);
|
||||
$result = array();
|
||||
$sql = "SELECT COUNT(*) FROM logins WHERE"
|
||||
. " localpart LIKE '%" . $term . "%';";
|
||||
$res = $this->db->query($sql);
|
||||
|
||||
if ($res->fetchColumn() > 0) {
|
||||
$sql = "SELECT first_name, last_name, localpart FROM logins WHERE"
|
||||
. " localpart LIKE '%" . $term . "%';";
|
||||
foreach ($this->db->query($sql) as $row) {
|
||||
array_push($result, [
|
||||
"display_name" => $first_name . " " . $last_name,
|
||||
"user_id" => $row["localpart"],
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function searchUserByEmail($search_term) {
|
||||
$term = filter_var($search_term, FILTER_SANITIZE_STRING);
|
||||
$result = array();
|
||||
$sql = "SELECT COUNT(*) FROM logins WHERE"
|
||||
. " email = '" . $term . "';";
|
||||
$res = $this->db->query($sql);
|
||||
|
||||
if ($res->fetchColumn() > 0) {
|
||||
$sql = "SELECT first_name, last_name, localpart FROM logins WHERE"
|
||||
. " email = '" . $term . "';";
|
||||
foreach ($this->db->query($sql) as $row) {
|
||||
array_push($result, [
|
||||
"display_name" => $first_name . " " . $last_name,
|
||||
"user_id" => $row["localpart"],
|
||||
]);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($mx_db)) {
|
||||
|
||||
33
internal/directory_lookup.php
Normal file
33
internal/directory_lookup.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
require_once("../database.php");
|
||||
$response=[
|
||||
"limited" => false,
|
||||
"result" => [],
|
||||
];
|
||||
|
||||
try {
|
||||
$inputJSON = file_get_contents('php://input');
|
||||
$input = json_decode($inputJSON, TRUE);
|
||||
if (!isset($input["by"])) {
|
||||
throw new Exception('"id" is not defined');
|
||||
}
|
||||
if (!isset($input["search_term"])) {
|
||||
throw new Exception('"search_term" is not defined');
|
||||
}
|
||||
switch ($input["by"]) {
|
||||
case "name":
|
||||
$response["result"] = $mx_db->searchUserByName($input["search_term"]);
|
||||
break;
|
||||
case "threepid":
|
||||
$response["result"] = $mx_db->searchUserByEmail($input["search_term"]);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("unknown type for \"by\" param");
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("ídentity_bulk failed with error: " . $e->getMessage());
|
||||
$response["error"] = $e->getMessage();
|
||||
}
|
||||
print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
|
||||
?>
|
||||
49
internal/identity_bulk.php
Normal file
49
internal/identity_bulk.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
require_once("../database.php");
|
||||
$response = [
|
||||
"lookup" => []
|
||||
];
|
||||
try {
|
||||
$inputJSON = file_get_contents('php://input');
|
||||
$input = json_decode($inputJSON, TRUE);
|
||||
if (!isset($input["lookup"])) {
|
||||
throw new Exception('"lookup" is not defined');
|
||||
}
|
||||
if (!is_array($input["lookup"])) {
|
||||
throw new Exception('"lookup" is not an array');
|
||||
}
|
||||
foreach ($input["lookup"] as $lookup) {
|
||||
if (!isset($lookup["medium"])) {
|
||||
throw new Exception('"lookup.medium" is not defined');
|
||||
}
|
||||
if (!isset($lookup["address"])) {
|
||||
throw new Exception('"lookup.address" is not defined');
|
||||
}
|
||||
$res2 = array();
|
||||
switch ($lookup["medium"]) {
|
||||
case "email":
|
||||
$res2 = $mx_db->searchUserByEmail($input["lookup"]["address"]);
|
||||
if (!empty($res2)) {
|
||||
array_push($response["lookup"], [
|
||||
"medium" => $lookup["medium"],
|
||||
"address" => $lookup["address"],
|
||||
"id" => [
|
||||
"type" => "localpart",
|
||||
"value" => $res2[0]["user_id"],
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
case "msisdn":
|
||||
error_log("sb requested a bulk lookup for msisdn");
|
||||
break;
|
||||
default:
|
||||
throw new Exception("unknown type for \"by\" param");
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("ídentity_bulk failed with error: " . $e->getMessage());
|
||||
$response["error"] = $e->getMessage();
|
||||
}
|
||||
print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
|
||||
?>
|
||||
43
internal/identity_single.php
Normal file
43
internal/identity_single.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once("../database.php");
|
||||
$response = array();
|
||||
try {
|
||||
$inputJSON = file_get_contents('php://input');
|
||||
$input = json_decode($inputJSON, TRUE);
|
||||
if (!isset($input["lookup"])) {
|
||||
throw new Exception('"lookup" is not defined');
|
||||
}
|
||||
if (!isset($input["lookup"]["medium"])) {
|
||||
throw new Exception('"lookup.medium" is not defined');
|
||||
}
|
||||
if (!isset($input["lookup"]["address"])) {
|
||||
throw new Exception('"lookup.address" is not defined');
|
||||
}
|
||||
$res2 = array();
|
||||
switch ($input["lookup"]["medium"]) {
|
||||
case "email":
|
||||
$res2 = $mx_db->searchUserByEmail($input["lookup"]["address"]);
|
||||
if (!empty($res2)) {
|
||||
$response = [
|
||||
"lookup" => [
|
||||
"medium" => $input["lookup"]["medium"],
|
||||
"address" => $input["lookup"]["address"],
|
||||
"id" => [
|
||||
"type" => "localpart",
|
||||
"value" => $res2[0]["user_id"],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new Exception("unknown type for \"by\" param");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log("ídentity_bulk failed with error: " . $e->getMessage());
|
||||
$response["error"] = $e->getMessage();
|
||||
}
|
||||
print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
|
||||
?>
|
||||
@@ -5,7 +5,6 @@ $response = [
|
||||
]
|
||||
];
|
||||
|
||||
require_once("../config.php");
|
||||
require_once("../database.php");
|
||||
abstract class LoginRequester {
|
||||
const UNDEFINED = 0;
|
||||
|
||||
Reference in New Issue
Block a user