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
This commit is contained in:
@@ -172,12 +172,10 @@ class mxDatabase
|
|||||||
*/
|
*/
|
||||||
function addRegistration($first_name, $last_name, $username, $note, $email) {
|
function addRegistration($first_name, $last_name, $username, $note, $email) {
|
||||||
if ($this->userPendingRegistrations($username)) {
|
if ($this->userPendingRegistrations($username)) {
|
||||||
require_once("language.php");
|
throw new Exception("USERNAME_PENDING_REGISTRATION");
|
||||||
throw new Exception($language["USERNAME_PENDING_REGISTRATION"]." (requested)");
|
|
||||||
}
|
}
|
||||||
if ($this->userRegistered($username)) {
|
if ($this->userRegistered($username)) {
|
||||||
require_once("language.php");
|
throw new Exception("USERNAME_REGISTERED");
|
||||||
throw new Exception($language["USERNAME_REGISTERED"] . " (registered)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$verify_token = bin2hex(random_bytes(16));
|
$verify_token = bin2hex(random_bytes(16));
|
||||||
|
|||||||
@@ -20,32 +20,32 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
try {
|
try {
|
||||||
if (!isset($_SESSION["token"]) || !isset($_POST["token"]) || $_SESSION["token"] != $_POST["token"]) {
|
if (!isset($_SESSION["token"]) || !isset($_POST["token"]) || $_SESSION["token"] != $_POST["token"]) {
|
||||||
// token not present or invalid
|
// token not present or invalid
|
||||||
throw new Exception($language["UNKNOWN_SESSION"]);
|
throw new Exception("UNKNOWN_SESSION");
|
||||||
}
|
}
|
||||||
if (!isset($_POST["username"])) {
|
if (!isset($_POST["username"])) {
|
||||||
throw new Exception($language["UNKNOWN_USERNAME"]);
|
throw new Exception("UNKNOWN_USERNAME");
|
||||||
}
|
}
|
||||||
if (strlen($_POST["username"] > 20 || strlen($_POST["username"]) < 3)) {
|
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) {
|
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"] &&
|
if (isset($config["getPasswordOnRegistration"]) && $config["getPasswordOnRegistration"] &&
|
||||||
$_POST["password"] != $_POST["password_confirm"]) {
|
$_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) {
|
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)) {
|
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"])) {
|
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"])) {
|
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);
|
$first_name = filter_var($_POST["first_name"], FILTER_SANITIZE_STRING);
|
||||||
@@ -87,7 +87,11 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|||||||
print("<title>" . $language["REGISTRATION_REQUEST_FAILED"] . "</title>");
|
print("<title>" . $language["REGISTRATION_REQUEST_FAILED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
print("<h1>" . $language["REGISTRATION_REQUEST_FAILED"] . "</h1>");
|
||||||
|
if (isset($language[$e->getMessage()])) {
|
||||||
|
print("<p>" . $language[$e->getMessage()] . "</p>");
|
||||||
|
} else {
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
|
}
|
||||||
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ try {
|
|||||||
throw new Exception("Method not allowed");
|
throw new Exception("Method not allowed");
|
||||||
}
|
}
|
||||||
if (!isset($_GET["t"])) {
|
if (!isset($_GET["t"])) {
|
||||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
throw new Exception("UNKNOWN_TOKEN");
|
||||||
}
|
}
|
||||||
$token = filter_var($_GET["t"], FILTER_SANITIZE_STRING);
|
$token = filter_var($_GET["t"], FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ try {
|
|||||||
|
|
||||||
$user = $mx_db->getUserForVerify($token);
|
$user = $mx_db->getUserForVerify($token);
|
||||||
if ($user == NULL) {
|
if ($user == NULL) {
|
||||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
throw new Exception("UNKNOWN_TOKEN");
|
||||||
}
|
}
|
||||||
$first_name = $user["first_name"];
|
$first_name = $user["first_name"];
|
||||||
$last_name = $user["last_name"];
|
$last_name = $user["last_name"];
|
||||||
@@ -69,7 +69,11 @@ try {
|
|||||||
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
print("<title>" . $language["VERIFICATION_FAILED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
print("<h1>" . $language["VERIFICATION_FAILED"] . "</h1>");
|
||||||
|
if (isset($language[$e->getMessage()])) {
|
||||||
|
print("<p>" . $language[$e->getMessage()] . "</p>");
|
||||||
|
} else {
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
|
}
|
||||||
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ try {
|
|||||||
throw new Exception("Method not allowed");
|
throw new Exception("Method not allowed");
|
||||||
}
|
}
|
||||||
if (!isset($_GET["t"])) {
|
if (!isset($_GET["t"])) {
|
||||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
throw new Exception("UNKNOWN_TOKEN");
|
||||||
}
|
}
|
||||||
$token = filter_var($_GET["t"], FILTER_SANITIZE_STRING);
|
$token = filter_var($_GET["t"], FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ try {
|
|||||||
|
|
||||||
$user = $mx_db->getUserForApproval($token);
|
$user = $mx_db->getUserForApproval($token);
|
||||||
if ($user == NULL) {
|
if ($user == NULL) {
|
||||||
throw new Exception($language["UNKNOWN_TOKEN"]);
|
throw new Exception("UNKNOWN_TOKEN");
|
||||||
}
|
}
|
||||||
|
|
||||||
$first_name = $user["first_name"];
|
$first_name = $user["first_name"];
|
||||||
@@ -74,7 +74,7 @@ try {
|
|||||||
$mxMsg->set_type("m.text");
|
$mxMsg->set_type("m.text");
|
||||||
$mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . ".");
|
$mxMsg->set_body("Fehler beim Registrieren von " . $first_name . " " . $last_name . ".");
|
||||||
$mxConn->send($config["register_room"], $mxMsg);
|
$mxConn->send($config["register_room"], $mxMsg);
|
||||||
throw new Exception($language["REGISTRATION_FAILED"]);
|
throw new Exception("REGISTRATION_FAILED");
|
||||||
}
|
}
|
||||||
|
|
||||||
print("<title>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</title>");
|
print("<title>" . $language["ADMIN_VERIFY_SITE_TITLE"] . "</title>");
|
||||||
@@ -160,7 +160,11 @@ background: rgba(255, 255, 255, 0.8);
|
|||||||
print("<title>" . $language["REGISTRATION_FAILED"] . "</title>");
|
print("<title>" . $language["REGISTRATION_FAILED"] . "</title>");
|
||||||
print("</head><body>");
|
print("</head><body>");
|
||||||
print("<h1>" . $language["REGISTRATION_FAILED"] . "</h1>");
|
print("<h1>" . $language["REGISTRATION_FAILED"] . "</h1>");
|
||||||
|
if (isset($language[$e->getMessage()])) {
|
||||||
|
print("<p>" . $language[$e->getMessage()] . "</p>");
|
||||||
|
} else {
|
||||||
print("<p>" . $e->getMessage() . "</p>");
|
print("<p>" . $e->getMessage() . "</p>");
|
||||||
|
}
|
||||||
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
print("<a href=\"" . $config["webroot"] . "/index.php" . "\">Zur Registrierungsseite</a>");
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user