diff --git a/config.sample.php b/config.sample.php index 12152c8..717c35e 100644 --- a/config.sample.php +++ b/config.sample.php @@ -11,7 +11,13 @@ $config = [ "webroot" => "https://myregisterdomain.net/", // optional: Do you have a place where howTo's are located? If not leave this value out "howToURL" => "https://my-url-for-storing-howTos.net", + // set the mode of operation. Basically this defines where the data is stored: + // - synapse (using the register endpoint - so no further auth config necessary + // - local (recommended; using a table in the database to store credentials; + // synapse has to be configured to use that) + "operationMode" => "local", // When you want to collect the password on registration set this to true + // only evaluated when operationMode = local "getPasswordOnRegistration" => false, // to define where the data should be stored: "databaseURI" => "sqlite:" . dirname(__FILE__) . "/db_file.sqlite", diff --git a/database.php b/database.php index d654c66..fef634c 100644 --- a/database.php +++ b/database.php @@ -241,7 +241,7 @@ class mxDatabase { $res = $this->db->query($sql); if ($res->fetchColumn() > 0) { - $sql = "SELECT first_name, last_name, note, email, admin_token FROM registrations " + $sql = "SELECT first_name, last_name, note, email, username, admin_token FROM registrations " . " WHERE verify_token = '" . $verify_token . "'" . " AND state = " . RegisterState::PendingEmailVerify . " LIMIT 1;"; foreach ($this->db->query($sql) as $row) { diff --git a/internal/directory_search.php b/internal/directory_search.php index d6419cd..2149a82 100644 --- a/internal/directory_search.php +++ b/internal/directory_search.php @@ -46,5 +46,5 @@ try { error_log("failed with error: " . $e->getMessage()); $response["error"] = $e->getMessage(); } -print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); +print (json_encode($response, JSON_PRETTY_PRINT)); ?> diff --git a/internal/identity_bulk.php b/internal/identity_bulk.php index 120871e..8c87e12 100644 --- a/internal/identity_bulk.php +++ b/internal/identity_bulk.php @@ -66,5 +66,5 @@ try { error_log("ídentity_bulk failed with error: " . $e->getMessage()); $response["error"] = $e->getMessage(); } -print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); +print (json_encode($response, JSON_PRETTY_PRINT)); ?> diff --git a/internal/identity_single.php b/internal/identity_single.php index 8a317d9..fde3dd8 100644 --- a/internal/identity_single.php +++ b/internal/identity_single.php @@ -61,5 +61,5 @@ try { "error" => $e->getMessage() ]; } -print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); +print (json_encode($response, JSON_PRETTY_PRINT)); ?> diff --git a/internal/login.php b/internal/login.php index 57d7685..9f44dbe 100644 --- a/internal/login.php +++ b/internal/login.php @@ -108,5 +108,5 @@ try { error_log("Auth failed with error: " . $e->getMessage()); $response["auth"]["error"] = $e->getMessage(); } -print (json_encode($response, JSON_PRETTY_PRINT) . "\n"); +print (json_encode($response, JSON_PRETTY_PRINT)); ?> diff --git a/public/index.php b/public/index.php index 735a24e..ede9a46 100644 --- a/public/index.php +++ b/public/index.php @@ -13,12 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -require_once "../language.php"; -if (!file_exists("../config.php")) { - print($language["NO_CONFIGURATION"]); - exit(); -} -require_once "../config.php"; // enforce admin via https if (!isset($_SERVER['HTTPS'])) { @@ -26,6 +20,25 @@ if (!isset($_SERVER['HTTPS'])) { exit(); } +require_once "../language.php"; +if (!file_exists("../config.php")) { + print($language["NO_CONFIGURATION"]); + exit(); +} +require_once "../config.php"; + +// this values will not be used when using the register operation type +$storeFirstLastName = false; +if (isset($config["operationMode"]) && $config["operationMode"] === "local") { + $storeFirstLastName = true; +} + +// currently the case to store the password on our own is the only supported one +$storePassword = false; +if (isset($config["getPasswordOnRegistration"]) && $config["getPasswordOnRegistration"] && + isset($config["operationMode"]) && $config["operationMode"] === "synapse") { + $storePassword = true; +} session_start(); if ($_SERVER["REQUEST_METHOD"] == "POST") { @@ -53,17 +66,22 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if (!isset($_POST["email"]) || !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) { throw new Exception("EMAIL_INVALID_FORMAT"); } - if (isset($_POST["first_name"]) && ! preg_match("/[A-Z][a-z]+/", $_POST["first_name"])) { - throw new Exception("FIRSTNAME_INVALID_FORMAT"); - } - if (isset($_POST["last_name"]) && ! preg_match("/[A-Z][a-z]+/", $_POST["last_name"])) { - throw new Exception("SIRNAME_INVALID_FORMAT"); - } + if ($storeFirstLastName) { + // only require first_name and last_name when we will evaluate them + if (!isset($_POST["first_name"]) || ! preg_match("/[A-Z][a-z]+/", $_POST["first_name"])) { + throw new Exception("FIRSTNAME_INVALID_FORMAT"); + } + if (!isset($_POST["last_name"]) || ! preg_match("/[A-Z][a-z]+/", $_POST["last_name"])) { + throw new Exception("SIRNAME_INVALID_FORMAT"); + } + $first_name = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING); + $last_name = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING); + } else { + $first_name = $last_name = ""; + } - $first_name = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING); - $last_name = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING); $username = filter_var($_POST["username"], FILTER_SANITIZE_STRING); - if (isset($_POST["password"])) { + if ($storePassword && isset($_POST["password"])) { $password = filter_var($_POST["password"], FILTER_SANITIZE_STRING); } $note = filter_var($_POST["note"], FILTER_SANITIZE_STRING); @@ -82,7 +100,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { require_once "../mail_templates.php"; $success = send_mail_pending_verification( $config["homeserver"], - $first_name . " " . $last_name, + $storeFirstLastName ? $first_name . " " . $last_name : $username, $email, $verify_url); @@ -137,6 +155,7 @@ body{