20 || strlen($username) < 3) { throw new Exception("USERNAME_INVALID"); } if (!ctype_alnum($username)) { throw new Exception("USERNAME_NOT_ALNUM"); } if (!strcmp($username, strtolower($username))) { throw new Exception("USERNAME_INVALID"); } if ($storePassword && (!isset($_POST["password"]) || !isset($_POST["password_confirm"]))) { throw new Exception("PASSWORD_NOT_PROVIDED"); } if ($storePassword && $_POST["password"] != $_POST["password_confirm"]) { throw new Exception("PASSWORD_NOT_MATCH"); } if (isset($_POST["note"]) && strlen($_POST["note"]) > 50) { throw new Exception("NOTE_LENGTH_EXEEDED"); } if (!isset($_POST["email"]) || !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) { throw new Exception("EMAIL_INVALID_FORMAT"); } if ($storeFirstLastName) { // only require first_name and last_name when we will evaluate them if (!isset($_POST["first_name"]) || !preg_match("/[A-Z][a-z]+/", $_POST["first_name"])) { throw new Exception("FIRSTNAME_INVALID_FORMAT"); } if (!isset($_POST["last_name"]) || !preg_match("/[A-Z][a-z]+/", $_POST["last_name"])) { throw new Exception("SIRNAME_INVALID_FORMAT"); } $first_name = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING); $last_name = filter_var($_POST["last_name"], FILTER_SANITIZE_STRING); } else { $first_name = $last_name = ""; } $password = ""; if ($storePassword && isset($_POST["password"])) { $password = filter_var($_POST["password"], FILTER_SANITIZE_STRING); } $note = filter_var($_POST["note"], FILTER_SANITIZE_STRING); $email = filter_var($_POST["email"], FILTER_VALIDATE_EMAIL); require_once(__DIR__ . "/../database.php"); $res = $mx_db->addRegistration($first_name, $last_name, $username, $password, $note, $email); if (!isset($res["verify_token"])) { error_log("sth. went wrong. registration did not throw but admin_token not set"); throw Exception("UNKNOWN_ERROR"); } $verify_token = $res["verify_token"]; $verify_url = $config["webroot"] . "/verify.php?t=" . $verify_token; require_once(__DIR__ . "/../mail_templates.php"); $success = send_mail_pending_verification( $config["homeserver"], $storeFirstLastName ? $first_name . " " . $last_name : $username, $email, $verify_url); $mx_db->setRegistrationStateVerify( ($success ? RegisterState::PendingEmailVerify : RegisterState::PendingEmailSend), $verify_token); print("" . $language["SUCCESS"] . ""); print(""); print("

" . $language["SUCCESS"] . "

"); print("

" . $language["TASK_CHECK_YOUR_EMAIL_VERIFY"] . "

"); print("" . $language["JUMP_TO_HOMEPAGE"] . ""); } catch (Exception $e) { print("" . $language["REGISTRATION_REQUEST_FAILED"] . ""); print(""); print("

" . $language["REGISTRATION_REQUEST_FAILED"] . "

"); if (isset($language[$e->getMessage()])) { print("

" . $language[$e->getMessage()] . "

"); } else { print("

" . $e->getMessage() . "

"); } print("" . $language["JUMP_TO_HOMEPAGE"] . ""); } } else { $_SESSION["token"] = bin2hex(random_bytes(16)); ?> <?php echo strtr($language["TOPIC_PLEASE_REGISTER"], ["@homeserver" => $config["homeserver"]]); ?>

$config["homeserver"]]) . "" . $language["TOPIC_PLEASE_REGISTER_NOTE"] . ""; ?>

" pattern="[A-Z][a-z]+">
" pattern="[A-Z][a-z]+">
" required>
">
" pattern="[a-z1-9]{3,20}" required>
" required>
" required>
"> " class="btn btn-info btn-block">
" . $language["NOTE"] . ":
"; echo strtr($language["NOTE_FOR_REGISTRATION"], ["@homeserver" => $config["homeserver"]]); echo "

"; } ?>