From facdad126b904da80e237670af112df22a14a64c Mon Sep 17 00:00:00 2001 From: Krombel Date: Mon, 19 Mar 2018 14:40:20 +0100 Subject: [PATCH] fix language reference it was the case that the language string for Exceptions was not resolved successfully in some cases. Now we switch to passing the internal string via Exceptions which then will be used to translate to the correct language when needed --- database.php | 6 ++---- public/index.php | 24 ++++++++++++++---------- public/verify.php | 10 +++++++--- public/verify_admin.php | 12 ++++++++---- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/database.php b/database.php index d33d6cf..18f00c6 100644 --- a/database.php +++ b/database.php @@ -172,12 +172,10 @@ class mxDatabase */ function addRegistration($first_name, $last_name, $username, $note, $email) { if ($this->userPendingRegistrations($username)) { - require_once("language.php"); - throw new Exception($language["USERNAME_PENDING_REGISTRATION"]." (requested)"); + throw new Exception("USERNAME_PENDING_REGISTRATION"); } if ($this->userRegistered($username)) { - require_once("language.php"); - throw new Exception($language["USERNAME_REGISTERED"] . " (registered)"); + throw new Exception("USERNAME_REGISTERED"); } $verify_token = bin2hex(random_bytes(16)); diff --git a/public/index.php b/public/index.php index 4c1f56c..79dce94 100644 --- a/public/index.php +++ b/public/index.php @@ -20,32 +20,32 @@ 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($language["UNKNOWN_SESSION"]); + throw new Exception("UNKNOWN_SESSION"); } if (!isset($_POST["username"])) { - throw new Exception($language["UNKNOWN_USERNAME"]); + throw new Exception("UNKNOWN_USERNAME"); } if (strlen($_POST["username"] > 20 || strlen($_POST["username"]) < 3)) { - throw new Exception($language["USERNAME_LENGTH_INVALID"]); + throw new Exception("USERNAME_LENGTH_INVALID"); } if (ctype_alnum($_POST['username']) != true) { - throw new Exception($language["USERNAME_NOT_ALNUM"]); + throw new Exception("USERNAME_NOT_ALNUM"); } if (isset($config["getPasswordOnRegistration"]) && $config["getPasswordOnRegistration"] && $_POST["password"] != $_POST["password_confirm"]) { - throw new Exception($language["PASSWORD_NOT_MATCH"]); + throw new Exception("PASSWORD_NOT_MATCH"); } if (isset($_POST["note"]) && strlen($_POST["note"]) > 50) { - throw new Exception($language["NOTE_LENGTH_EXEEDED"]); + throw new Exception("NOTE_LENGTH_EXEEDED"); } if (!isset($_POST["email"]) || !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) { - throw new Exception($language["EMAIL_INVALID_FORMAT"]); + throw new Exception("EMAIL_INVALID_FORMAT"); } if (isset($_POST["first_name"]) && ! preg_match("/[A-Z][a-z]+/", $_POST["first_name"])) { - throw new Exception($language["FIRSTNAME_INVALID_FORMAT"]); + throw new Exception("FIRSTNAME_INVALID_FORMAT"); } if (isset($_POST["last_name"]) && ! preg_match("/[A-Z][a-z]+/", $_POST["last_name"])) { - throw new Exception($language["SIRNAME_INVALID_FORMAT"]); + throw new Exception("SIRNAME_INVALID_FORMAT"); } $first_name = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING); @@ -87,7 +87,11 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { print("" . $language["REGISTRATION_REQUEST_FAILED"] . ""); print(""); print("

" . $language["REGISTRATION_REQUEST_FAILED"] . "

"); - print("

" . $e->getMessage() . "

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

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

"); + } else { + print("

" . $e->getMessage() . "

"); + } print("Zur Registrierungsseite"); } } else { diff --git a/public/verify.php b/public/verify.php index 38ac223..e19a578 100644 --- a/public/verify.php +++ b/public/verify.php @@ -22,7 +22,7 @@ try { throw new Exception("Method not allowed"); } if (!isset($_GET["t"])) { - throw new Exception($language["UNKNOWN_TOKEN"]); + throw new Exception("UNKNOWN_TOKEN"); } $token = filter_var($_GET["t"], FILTER_SANITIZE_STRING); @@ -30,7 +30,7 @@ try { $user = $mx_db->getUserForVerify($token); if ($user == NULL) { - throw new Exception($language["UNKNOWN_TOKEN"]); + throw new Exception("UNKNOWN_TOKEN"); } $first_name = $user["first_name"]; $last_name = $user["last_name"]; @@ -69,7 +69,11 @@ try { print("" . $language["VERIFICATION_FAILED"] . ""); print(""); print("

" . $language["VERIFICATION_FAILED"] . "

"); - print("

" . $e->getMessage() . "

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

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

"); + } else { + print("

" . $e->getMessage() . "

"); + } print("Zur Registrierungsseite"); } ?> diff --git a/public/verify_admin.php b/public/verify_admin.php index 15aa335..6b397d0 100644 --- a/public/verify_admin.php +++ b/public/verify_admin.php @@ -22,7 +22,7 @@ try { throw new Exception("Method not allowed"); } if (!isset($_GET["t"])) { - throw new Exception($language["UNKNOWN_TOKEN"]); + throw new Exception("UNKNOWN_TOKEN"); } $token = filter_var($_GET["t"], FILTER_SANITIZE_STRING); @@ -42,7 +42,7 @@ try { $user = $mx_db->getUserForApproval($token); if ($user == NULL) { - throw new Exception($language["UNKNOWN_TOKEN"]); + throw new Exception("UNKNOWN_TOKEN"); } $first_name = $user["first_name"]; @@ -74,7 +74,7 @@ try { $mxMsg->set_type("m.text"); $mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . "."); $mxConn->send($config["register_room"], $mxMsg); - throw new Exception($language["REGISTRATION_FAILED"]); + throw new Exception("REGISTRATION_FAILED"); } print("" . $language["ADMIN_VERIFY_SITE_TITLE"] . ""); @@ -160,7 +160,11 @@ background: rgba(255, 255, 255, 0.8); print("" . $language["REGISTRATION_FAILED"] . ""); print(""); print("

" . $language["REGISTRATION_FAILED"] . "

"); - print("

" . $e->getMessage() . "

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

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

"); + } else { + print("

" . $e->getMessage() . "

"); + } print("Zur Registrierungsseite"); } ?>