diff --git a/public/index.php b/public/index.php index ede9a46..af5ebe6 100644 --- a/public/index.php +++ b/public/index.php @@ -13,17 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - // enforce admin via https if (!isset($_SERVER['HTTPS'])) { - header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], true, 301); - exit(); + header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], true, 301); + exit(); } require_once "../language.php"; if (!file_exists("../config.php")) { - print($language["NO_CONFIGURATION"]); - exit(); + print($language["NO_CONFIGURATION"]); + exit(); } require_once "../config.php"; @@ -36,219 +35,215 @@ if (isset($config["operationMode"]) && $config["operationMode"] === "local") { // currently the case to store the password on our own is the only supported one $storePassword = false; if (isset($config["getPasswordOnRegistration"]) && $config["getPasswordOnRegistration"] && - isset($config["operationMode"]) && $config["operationMode"] === "synapse") { + isset($config["operationMode"]) && $config["operationMode"] === "synapse") { $storePassword = true; } session_start(); if ($_SERVER["REQUEST_METHOD"] == "POST") { - try { - if (!isset($_SESSION["token"]) || !isset($_POST["token"]) || $_SESSION["token"] != $_POST["token"]) { - // token not present or invalid - throw new Exception("UNKNOWN_SESSION"); - } - if (!isset($_POST["username"])) { - throw new Exception("UNKNOWN_USERNAME"); - } - if (strlen($_POST["username"] > 20 || strlen($_POST["username"]) < 3)) { - throw new Exception("USERNAME_LENGTH_INVALID"); - } - if (ctype_alnum($_POST['username']) != true) { - throw new Exception("USERNAME_NOT_ALNUM"); - } - if (isset($config["getPasswordOnRegistration"]) && $config["getPasswordOnRegistration"] && - $_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 = ""; - } + try { + if (!isset($_SESSION["token"]) || !isset($_POST["token"]) || $_SESSION["token"] != $_POST["token"]) { + // token not present or invalid + throw new Exception("UNKNOWN_SESSION"); + } + if (!isset($_POST["username"])) { + throw new Exception("UNKNOWN_USERNAME"); + } + if (strlen($_POST["username"] > 20 || strlen($_POST["username"]) < 3)) { + throw new Exception("USERNAME_LENGTH_INVALID"); + } + if (ctype_alnum($_POST['username']) != true) { + throw new Exception("USERNAME_NOT_ALNUM"); + } + if (isset($config["getPasswordOnRegistration"]) && $config["getPasswordOnRegistration"] && + $_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 = ""; + } - $username = filter_var($_POST["username"], FILTER_SANITIZE_STRING); - 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); + $username = filter_var($_POST["username"], FILTER_SANITIZE_STRING); + 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("../database.php"); - $res = $mx_db->addRegistration($first_name, $last_name, $username, $note, $email); + require_once("../database.php"); + $res = $mx_db->addRegistration($first_name, $last_name, $username, $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"]; + 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 "../mail_templates.php"; - $success = send_mail_pending_verification( - $config["homeserver"], - $storeFirstLastName ? $first_name . " " . $last_name : $username, - $email, - $verify_url); + $verify_url = $config["webroot"] . "/verify.php?t=" . $verify_token; + require_once "../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); + $mx_db->setRegistrationStateVerify( + ($success ? RegisterState::PendingEmailVerify : RegisterState::PendingEmailSend), $verify_token); - print("
Bitte überprüfe deine E-Mails um deine E-Mail-Adresse zu bestätigen.
"); - print("Zur Registrierungsseite"); - } catch (Exception $e) { - print("" . $language[$e->getMessage()] . "
"); - } else { - print("" . $e->getMessage() . "
"); - } - print("Zur Registrierungsseite"); - } + print("Bitte überprüfe deine E-Mails um deine E-Mail-Adresse zu bestätigen.
"); + print("Zur Registrierungsseite"); + } catch (Exception $e) { + print("" . $language[$e->getMessage()] . "
"); + } else { + print("" . $e->getMessage() . "
"); + } + print("Zur Registrierungsseite"); + } } else { - $_SESSION["token"] = bin2hex(random_bytes(16)); -?> -Hinweis:
- ist ein geschlossenes Chat-Netzwerk in dem jeder Nutzer bestätigt werden muss.
- Du bekommst eine E-Mail wenn jemand deine Mitgliedschaft bestätigt hat. An diese wird auch dein initiales Passwort gesendet.
- Hinterlasse also bitte einen Hinweis zu dir (der nur den entsprechenden Personen gezeigt wird).
- Liebe Grüße vom Team von
-
Hinweis:
+ ist ein geschlossenes Chat-Netzwerk in dem jeder Nutzer bestätigt werden muss.
+ Du bekommst eine E-Mail wenn jemand deine Mitgliedschaft bestätigt hat. An diese wird auch dein initiales Passwort gesendet.
+ Hinterlasse also bitte einen Hinweis zu dir (der nur den entsprechenden Personen gezeigt wird).
+ Liebe Grüße vom Team von
+