diff --git a/cron.php b/cron.php
index 0a01e65..4caedad 100644
--- a/cron.php
+++ b/cron.php
@@ -1,9 +1,17 @@
query($sql) as $row) {
// will only be executed once
$first_name = $row["first_name"];
@@ -13,34 +21,75 @@ foreach ($db->query($sql) as $row) {
$state = $row["state"];
try {
-
switch ($state) {
- case RegisterState::RegistrationAccepted:
- // Registration got accepted but registration failed
+ case RegisterState::PendingEmailSend:
+ $verify_url = $webroot . "/verify.php?t=" . $row["verify_token"];
+ $success = send_mail_pending_verification(
+ $homeserver,
+ $row["first_name"] . " " . $row["last_name"],
+ $row["email"],
+ $row["verify_url"]);
- // 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);
+ if ($success) {
+ $db->exec("UPDATE registrations SET state = " . RegisterState::PendingEmailVerify)
+ . " WHERE id = " . $row["id"] . ";");
+ } else {
+ throw new Exception("Could not send mail to ".$row["first_name"]." ".$row["last_name"]."(".$row["id"].")");
+ }
+ break;
+ case RegisterState::PendingAdminSend:
+ require_once("../MatrixConnection.php");
+ $adminUrl = $webroot . "/verify_admin.php?t=" . $admin_token;
+ $mxConn = new MatrixConnection($homeserver, $access_token);
$mxMsg = new MatrixMessage();
+ $mxMsg->set_body($first_name . ' ' . $last_name . "möchte sich registrieren und hat folgende Notiz hinterlassen:\r\n"
+ . $note . "\r\n"
+ . "Zum Bearbeiten hier klicken:\r\n" . $adminUrl);
+ $mxMsg->set_formatted_body($first_name . ' ' . $last_name . " möchte sich registrieren und hat folgende Notiz hinterlassen:
"
+ . $note . "
"
+ . "Zum Bearbeiten hier klicken");
$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;
+ $response = $mxConn->send($register_room, $mxMsg);
- case RegisterState::RegistrationDeclined:
- break;
+ if ($response) {
+ $db->exec("UPDATE registrations SET state = " . RegisterState::PendingAdminVerify
+ . " WHERE id = " . $row["id"] . "';");
+
+ send_mail_pending_approval($homeserver, $first_name . " " . $last_name, $email);
+ } else {
+ throw new Exception("Could not send notification for ".$row["first_name"]." ".$row["last_name"]."(".$row["id"].") to admins.");
+ }
+ break;
+ case RegisterState::PendingRegistration:
+ // 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::PendingSendRegistrationMail:
+ print ("Error: Unhandled state: PendingSendRegistrationMail for " . $first_name . " " . $last_name . " (" . $username . ")");
+ break;
+ case RegisterState::RegistrationDeclined:
+ case RegisterState::AllDone:
+ // do reqular cleanup
+ break;
}
} catch (Exception $e) {
print("Error while handling cron for " . $first_name . " " . $last_name . " (" . $username . ")");
diff --git a/database.php b/database.php
index eee73a0..bf57af9 100644
--- a/database.php
+++ b/database.php
@@ -19,7 +19,7 @@ abstract class RegisterState
// State to allow persisting in the database although an admin declined it.
// Will be removed regularly
- const RegistrationAccepted = 12;
+ const RegistrationAccepted = 6;
const RegistrationDeclined = 13;
// User got successfully registered. Will be cleaned up later
diff --git a/public/verify_admin.php b/public/verify_admin.php
index 0b56954..7ba51fd 100644
--- a/public/verify_admin.php
+++ b/public/verify_admin.php
@@ -1,5 +1,5 @@
-
" . $language["ADMIN_REGISTER_ACCEPTED_BODY"] . "
"); } elseif ($action == RegisterState::RegistrationDeclined) { $db->exec("UPDATE registrations SET state = " . RegisterState::RegistrationDeclined - . " WHERE admin_token = \"" . $token. "\";"); + . " WHERE admin_token = '" . $token. "';"); send_mail_registration_decline($homeserver, $first_name . " " . $last_name, $email, $decline_reason); print("" . $language["ADMIN_REGISTER_DECLINED_BODY"] . "
"); } else { - print("