diff --git a/config.sample.php b/config.sample.php index 4fce912..9e43883 100644 --- a/config.sample.php +++ b/config.sample.php @@ -19,6 +19,10 @@ $config = [ // - 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, diff --git a/language.php b/language.php index 145215e..14fe117 100644 --- a/language.php +++ b/language.php @@ -28,4 +28,4 @@ if (!file_exists($lang_file)) { $lang_file = dirname(__FILE__) . "/lang/lang." . $lang . ".php"; require_once($lang_file); unset($lang_file); -?> \ No newline at end of file +?> diff --git a/public/verify_admin.php b/public/verify_admin.php index 554c23e..9e98375 100644 --- a/public/verify_admin.php +++ b/public/verify_admin.php @@ -70,8 +70,25 @@ try { require_once("../MatrixConnection.php"); $mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]); - // generate a password with 8 characters - $password = $mx_db->addUser($first_name, $last_name, $username, $email); + $password = NULL; + switch ($config["operationMode"]) { + case "synapse": + // register with registration_shared_secret + // generate a password with 10 characters + $password = bin2hex(openssl_random_pseudo_bytes(5)); + $res = $mxConn->register($username, $password, $config["registration_shared_secret"]); + if (!$res) { + // something went wrong while registering + $password = NULL; + } + break; + case "local": + // register by adding a user to the local database + $password = $mx_db->addUser($first_name, $last_name, $username, $email); + break; + default: + throw new Exception("Unknown operationMode"); + } if ($password != NULL) { // send registration_success $res = send_mail_registration_success(