From 3250792c9d5520a97abd3ed1fb6ce57c603e1274 Mon Sep 17 00:00:00 2001 From: Krombel Date: Wed, 23 Jan 2019 15:44:21 +0100 Subject: [PATCH] fix empty string where only username is available --- public/index.php | 2 +- public/verify.php | 9 ++++++--- public/verify_admin.php | 11 +++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/public/index.php b/public/index.php index 75fe9c3..f4e062f 100644 --- a/public/index.php +++ b/public/index.php @@ -20,7 +20,7 @@ if (!isset($_SERVER['HTTPS'])) { } require_once(__DIR__ . "/../language.php"); -if (!file_exists("../config.php")) { +if (!file_exists(__DIR__ . "/../config.php")) { print($language["NO_CONFIGURATION"]); exit(); } diff --git a/public/verify.php b/public/verify.php index 7cbb2b4..05041a0 100644 --- a/public/verify.php +++ b/public/verify.php @@ -51,18 +51,21 @@ try { $email = $user["email"]; $admin_token = $user["admin_token"]; + // we have 2 cases: first and last name or just the username + $call_name = strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username; + require_once(__DIR__ . "/../MatrixConnection.php"); $adminUrl = $config["webroot"] . "/verify_admin.php?t=" . $admin_token; $mxConn = new MatrixConnection($config["homeserver"], $config["access_token"]); $mxMsg = new MatrixMessage(); $mxMsg->set_body(strtr($language["MSG_USER_WANTS_REGISTER"], [ - "@name" => (strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username), + "@name" => $call_name, "@note" => $note, "@adminUrl" => $adminUrl ])); if (isset($language["MSG_USER_WANTS_REGISTER_FORMATTED"])) { $mxMsg->set_formatted_body(strtr($language["MSG_USER_WANTS_REGISTER_FORMATTED"], [ - "@name" => (strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username), + "@name" => $call_name, "@note" => $note, "@adminUrl" => $adminUrl ])); @@ -76,7 +79,7 @@ try { $mx_db->setRegistrationStateVerify( ($response ? RegisterState::PendingAdminVerify : RegisterState::PendingAdminSend), $token); - send_mail_pending_approval($config["homeserver"], $first_name . " " . $last_name, $email); + send_mail_pending_approval($config["homeserver"], $call_name, $email); print("" . $language["VERIFICATION_SUCEEDED"] . ""); print(""); diff --git a/public/verify_admin.php b/public/verify_admin.php index e3c6b09..5daa013 100644 --- a/public/verify_admin.php +++ b/public/verify_admin.php @@ -60,6 +60,9 @@ try { $first_name = $user["first_name"]; $last_name = $user["last_name"]; $username = $user["username"]; + // we have 2 cases: first and last name or just the username + $call_name = strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username; + $note = $user["note"]; $email = $user["email"]; @@ -99,7 +102,7 @@ try { // send registration_success $res = send_mail_registration_success( $config["homeserver"], - $first_name . " " . $last_name, + $call_name, $email, $username, // only send password when auto-created @@ -112,11 +115,11 @@ try { $mx_db->setRegistrationStateAdmin(RegisterState::PendingSendRegistrationMail, $token); } } else { - send_mail_registration_allowed_but_failed($config["homeserver"], $first_name . " " . $last_name, $email); + send_mail_registration_allowed_but_failed($config["homeserver"], $call_name, $email); $mxMsg = new MatrixMessage(); $mxMsg->set_type("m.text"); $mxMsg->set_body(strtr($language["REGISTRATION_FAILED_FOR"], [ - "@name" => strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username, + "@name" => $call_name, ])); $mxConn->send($config["register_room"], $mxMsg); throw new Exception("REGISTRATION_FAILED"); @@ -129,7 +132,7 @@ try { } elseif ($action == RegisterState::RegistrationDeclined) { $mx_db->setRegistrationStateAdmin(RegisterState::RegistrationDeclined, $token); send_mail_registration_decline( - $config["homeserver"], strlen($first_name . $last_name) > 0 ? $first_name . " " . $last_name : $username, $email, $decline_reason + $config["homeserver"], $call_name, $email, $decline_reason ); print("" . $language["ADMIN_VERIFY_SITE_TITLE"] . ""); print("");