51 lines
1.6 KiB
PHP
51 lines
1.6 KiB
PHP
<?php
|
|
// This file is meant to do tasks that failed on the first attempt
|
|
|
|
|
|
$sql = "SELECT first_name, last_name, username, email, state FROM registrations WHERE admin_token = '" . $token
|
|
. "' AND state = " . RegisterState::PendingAdminVerify . " LIMIT 1;";
|
|
foreach ($db->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());
|
|
}
|
|
}
|
|
?>
|