diff --git a/config.sample.php b/config.sample.php
index 43a3370..9e43883 100644
--- a/config.sample.php
+++ b/config.sample.php
@@ -14,7 +14,17 @@ $config = [
// 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",
+
+ // This setting is only required for operationMode = synapse
+ "registration_shared_secret" => "SOME_SECRET_KEY_FROM_HOMESERVER_CONFIG"
+
// When you want to collect the password on registration set this to true
+ // only evaluated when operationMode = local
"getPasswordOnRegistration" => false,
// default language: one of [ en-gb | de-de ]
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/lang/lang.de-de.php b/lang/lang.de-de.php
index ded1271..d059bf9 100644
--- a/lang/lang.de-de.php
+++ b/lang/lang.de-de.php
@@ -1,4 +1,5 @@
"Die Registrierungsanfrage wurde akzeptiert. Der Nutzer wurde per Mail informiert.",
"ADMIN_REGISTER_DECLINED_BODY" => "Die Registrierungsanfrage wurde angelehnt. Der Nutzer wurde per Mail informiert.",
"JUMP_TO_HOMEPAGE" => "Zur Startseite",
- "TOPIC_PLEASE_REGISTER" => "Bitte für @homeserver registrieren2-Schritt-Registrierung",
+ "TOPIC_PLEASE_REGISTER" => "Bitte für @homeserver registrieren",
+ "TOPIC_PLEASE_REGISTER_NOTE" => "2-Schritt-Registrierung",
"NOTE_FOR_REGISTRATION" => "@homeserver ist ein geschlossenes Chat-Netzwerk in dem jeder Nutzer bestätigt werden muss.
Du bekommst eine E-Mail wenn jemand deine Mitgliedschaft bestätigt hat. An diese wird auch dein initiales Passwort gesendet.
Hinterlasse also bitte einen Hinweis zu dir (den nur die Administratoren sehen werden).
diff --git a/mail_templates.php b/mail_templates.php
index b3c9c23..3d62e3c 100644
--- a/mail_templates.php
+++ b/mail_templates.php
@@ -24,6 +24,7 @@ if (!file_exists($lang_file)) {
error_log("Mail templates for '" . $lang . "' not found. Fallback to 'de-de'");
$lang = "de-de";
}
+$lang_file = dirname(__FILE__) . "/lang/mail." . $lang . ".php";
require_once($lang_file);
unset($lang_file);
?>
diff --git a/public/index.php b/public/index.php
index 12fac63..df9db26 100644
--- a/public/index.php
+++ b/public/index.php
@@ -13,6 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+// enforce admin via https
+if (!isset($_SERVER['HTTPS'])) {
+ header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], true, 301);
+ exit();
+}
+
require_once "../language.php";
if (!file_exists("../config.php")) {
print($language["NO_CONFIGURATION"]);
@@ -20,12 +26,18 @@ if (!file_exists("../config.php")) {
}
require_once "../config.php";
-// enforce admin via https
-if (!isset($_SERVER['HTTPS'])) {
- header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], true, 301);
- exit();
+// 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 +65,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);
@@ -81,7 +98,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
$verify_url = $config["webroot"] . "/verify.php?t=" . $verify_token;
require_once "../mail_templates.php";
$success = send_mail_pending_verification(
- $config["homeserver"], $first_name . " " . $last_name, $email, $verify_url);
+ $config["homeserver"], $storeFirstLastName ? $first_name . " " . $last_name : $username, $email, $verify_url);
$mx_db->setRegistrationStateVerify(
($success ? RegisterState::PendingEmailVerify : RegisterState::PendingEmailSend), $verify_token);
@@ -105,7 +122,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
} else {
$_SESSION["token"] = bin2hex(random_bytes(16));
?>
-