3 Commits

Author SHA1 Message Date
5eeaa11c0c fix in config.sample 2018-04-16 15:17:58 +02:00
f74a2f74e0 fix path to config.php in mail.l.php 2018-04-16 15:15:32 +02:00
53ccd1c2b3 hopefully complete operationMode=synapse 2018-04-16 15:06:44 +02:00
5 changed files with 26 additions and 5 deletions

View File

@@ -19,6 +19,10 @@ $config = [
// - local (recommended; using a table in the database to store credentials; // - local (recommended; using a table in the database to store credentials;
// synapse has to be configured to use that) // synapse has to be configured to use that)
"operationMode" => "local", "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 // When you want to collect the password on registration set this to true
// only evaluated when operationMode = local // only evaluated when operationMode = local
"getPasswordOnRegistration" => false, "getPasswordOnRegistration" => false,

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
function send_mail($receiver, $subject, $body) { function send_mail($receiver, $subject, $body) {
include("config.php"); include("../config.php");
$headers = "From: " . $config["register_email"] . "\r\n" $headers = "From: " . $config["register_email"] . "\r\n"
. "Content-Type: text/plain;charset=utf-8"; . "Content-Type: text/plain;charset=utf-8";
return mail($receiver, $subject, $body, $headers); return mail($receiver, $subject, $body, $headers);

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
function send_mail($receiver, $subject, $body) { function send_mail($receiver, $subject, $body) {
include("config.php"); include("../config.php");
$headers = "From: " . $config["register_email"] . "\r\n" $headers = "From: " . $config["register_email"] . "\r\n"
. "Content-Type: text/plain;charset=utf-8"; . "Content-Type: text/plain;charset=utf-8";
return mail($receiver, $subject, $body, $headers); return mail($receiver, $subject, $body, $headers);

View File

@@ -70,8 +70,25 @@ try {
require_once("../MatrixConnection.php"); require_once("../MatrixConnection.php");
$mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]); $mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]);
// generate a password with 8 characters $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); $password = $mx_db->addUser($first_name, $last_name, $username, $email);
break;
default:
throw new Exception("Unknown operationMode");
}
if ($password != NULL) { if ($password != NULL) {
// send registration_success // send registration_success
$res = send_mail_registration_success( $res = send_mail_registration_success(