smaller optimizations

This commit is contained in:
2018-04-04 20:29:00 +02:00
parent b343c6f862
commit eb5b76c5c8
8 changed files with 24 additions and 22 deletions

View File

@@ -39,7 +39,7 @@ try {
$response["result"] = $mx_db->searchUserByEmail($input["search_term"]);
break;
default:
throw new Exception("unknown type for \"by\" param");
throw new Exception('unknown type for "by" param');
}
} catch (Exception $e) {

View File

@@ -37,7 +37,7 @@ try {
if (!isset($lookup["address"])) {
throw new Exception('"lookup.address" is not defined');
}
$res2 = array();
$res2 = NULL;
switch ($lookup["medium"]) {
case "email":
$res2 = $mx_db->searchUserByEmail($lookup["address"]);
@@ -54,9 +54,11 @@ try {
}
break;
case "msisdn":
// This is reserved for number lookups
throw new Exception("unimplemented lookup medium");
break;
default:
throw new Exception("unknown type for \"by\" param");
throw new Exception("unknown lookup medium");
}
}
} catch (Exception $e) {

View File

@@ -30,7 +30,7 @@ try {
if (!isset($input["lookup"]["address"])) {
throw new Exception('"lookup.address" is not defined');
}
$res2 = array();
$res2 = NULL;
switch ($input["lookup"]["medium"]) {
case "email":
$res2 = $mx_db->searchUserByEmail($input["lookup"]["address"]);
@@ -46,15 +46,19 @@ try {
]
];
}
break;
case "msisdn":
// This is reserved for number lookups
throw new Exception("unimplemented lookup medium");
break;
default:
throw new Exception("unknown type for \"by\" param");
throw new Exception("unknown lookup medium");
}
} catch (Exception $e) {
error_log("ídentity_bulk failed with error: " . $e->getMessage());
$response["error"] = $e->getMessage();
error_log("ídentity_single failed with error: " . $e->getMessage());
$response = [
"error" => $e->getMessage()
];
}
print (json_encode($response, JSON_PRETTY_PRINT) . "\n");
?>

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright 2018 Matthias Kesler
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// URL for this: /_matrix/client/r0/account/password?access_token=$ACCESS_TOKEN
header('Access-Control-Allow-Origin: *');
@@ -24,7 +24,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
// return with success
exit();
}
$response= new stdClass;
$response = new stdClass;
try {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE);
@@ -48,7 +48,7 @@ try {
$localpart = stripLocalpart($input["auth"]["user"]);
if (empty($localpart)) {
throw new Exception ("localpart cannot be identified");
throw new Exception("localpart cannot be identified");
}
require_once("../database.php");
@@ -59,7 +59,6 @@ try {
)) {
throw new Exception("invalid credentials or another error while updating");
}
} catch (Exception $e) {
header("HTTP/1.0 500 Internal Error");
error_log("failed with error: " . $e->getMessage());

View File

@@ -30,8 +30,7 @@ $loginRequester = LoginRequester::UNDEFINED;
try {
$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE);
$mxid = NULL;
$localpart = NULL;
$mxid = $localpart = NULL;
if (isset($input["user"])) {
if (isset($input["user"]["localpart"])) {
$localpart = $input["user"]["localpart"];
@@ -45,6 +44,8 @@ try {
$mxid = $input["user"]["mxid"];
$loginRequester = LoginRequester::MXISD;
}
} else {
throw new Exception('"user" not in request body');
}
// prefer the localpart attribute of mxisd. But in case of matrix-synapse-rest-auth
@@ -59,7 +60,7 @@ try {
}
$password = NULL;
if (isset($input["user"]) && isset($input["user"]["password"])) {
if (isset($input["user"]["password"])) {
$password = $input["user"]["password"];
}
if (empty($password)) {
@@ -95,6 +96,7 @@ try {
// only return that it was successful.
// we do not know how the data shall be transmitted so we do nothing with it
$response["auth"]["success"] = false;
$response["auth"]["error"] = "unidentified requester";
break;
}
} catch (Exception $e) {