From a51f44c01b17ac25c45ffd7a1e3d62ea2b94572b Mon Sep 17 00:00:00 2001 From: Krombel Date: Fri, 23 Feb 2018 17:50:02 +0100 Subject: [PATCH] add mail_templates and prepare cron.php --- cron.php | 50 ++++++++++++++++++++++++++ mail_templates.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 cron.php create mode 100644 mail_templates.php diff --git a/cron.php b/cron.php new file mode 100644 index 0000000..0a01e65 --- /dev/null +++ b/cron.php @@ -0,0 +1,50 @@ +query($sql) as $row) { + // will only be executed once + $first_name = $row["first_name"]; + $last_name = $row["last_name"]; + $username = $row["username"]; + $email = $row["email"]; + $state = $row["state"]; + + try { + + switch ($state) { + case RegisterState::RegistrationAccepted: + // Registration got accepted but registration failed + + // register user + require_once("MatrixConnection.php"); + $mxConn = new MatrixConnection($homeserver, $access_token); + + // generate a password with 8 characters + $password = bin2hex(openssl_random_pseudo_bytes(4)); + + $res = $mxConn->register($username, $password, $shared_secret); + if ($res) { + // send registration_success + send_mail_registration_success($homeserver, $first_name . " " . $last_name, $email, $username, $password, $howToURL); + } else { + send_mail_registration_allowed_but_failed($homeserver, $first_name . " " . $last_name, $email); + $mxMsg = new MatrixMessage(); + $mxMsg->set_type("m.text"); + $mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . "."); + $mxConn->send($mxMsg); + throw new Exception($language["REGISTRATION_FAILED"]); + } + break; + + case RegisterState::RegistrationDeclined: + break; + } + } catch (Exception $e) { + print("Error while handling cron for " . $first_name . " " . $last_name . " (" . $username . ")"); + print($e->getMessage()); + } +} +?> diff --git a/mail_templates.php b/mail_templates.php new file mode 100644 index 0000000..4245b69 --- /dev/null +++ b/mail_templates.php @@ -0,0 +1,90 @@ +