From 9ee0509fcf8a4e5952b59725768772d7e60f7d8e Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Wed, 11 Nov 2020 18:29:06 +0100 Subject: [PATCH] Localize error messages --- lang/en.php | 5 +++++ utils/changepass.php | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lang/en.php b/lang/en.php index 5ebb67d..0c9dfc6 100644 --- a/lang/en.php +++ b/lang/en.php @@ -101,9 +101,14 @@ $lang["edituser"] = "Edit user"; $lang["servererror"] = "Server error"; $lang["allrequired"] = "All fields are required"; $lang["passnotmatch"] = "Passwords don't match"; +$lang["oldpassinvalid"] = "Wrong old password"; +$lang["passempty"] = "Empty password"; +$lang["loginempty"] = "Empty login"; +$lang["passstrengthwarn"] = "Invalid password strength"; $lang["actionsuccess"] = "Action completed successfully"; $lang["actionfailure"] = "Something went wrong"; $lang["notauthorized"] = "User not authorized"; +$lang["userunknown"] = "User unknown"; $lang["userdelwarn"] = "Warning!\n\nYou are going to permanently delete user %s, together with all their routes and positions.\n\nAre you sure?"; // substitutes user login $lang["editinguser"] = "You are editing user %s"; // substitutes user login $lang["selfeditwarn"] = "Your can't edit your own user with this tool"; diff --git a/utils/changepass.php b/utils/changepass.php index 4452cad..c16355c 100644 --- a/utils/changepass.php +++ b/utils/changepass.php @@ -20,12 +20,15 @@ require_once(dirname(__DIR__) . "/helpers/auth.php"); require_once(ROOT_DIR . "/helpers/config.php"); require_once(ROOT_DIR . "/helpers/utils.php"); +require_once(ROOT_DIR . "/helpers/lang.php"); $auth = new uAuth(); $config = uConfig::getInstance(); +$lang = (new uLang($config))->getStrings(); + if (!$auth->isAuthenticated()) { $auth->sendUnauthorizedHeader(); - uUtils::exitWithError("Unauthorized"); + uUtils::exitWithError($lang["notauthorized"]); } $login = uUtils::postString('login'); @@ -33,31 +36,31 @@ $oldpass = uUtils::postPass('oldpass'); $pass = uUtils::postPass('pass'); // FIXME: strings need to be localized if (empty($pass)) { - uUtils::exitWithError("Empty password"); + uUtils::exitWithError($lang["passempty"]); } if (!$config->validPassStrength($pass)) { - uUtils::exitWithError("Invalid password strength"); + uUtils::exitWithError($lang["passstrengthwarn"]); } if (empty($login)) { - uUtils::exitWithError("Empty login"); + uUtils::exitWithError($lang["loginempty"]); } if ($auth->user->login === $login) { // current user $passUser = $auth->user; if (!$passUser->validPassword($oldpass)) { - uUtils::exitWithError("Wrong old password"); + uUtils::exitWithError($lang["oldpassinvalid"]); } } else if ($auth->isAdmin()) { // different user, only admin $passUser = new uUser($login); if (!$passUser->isValid) { - uUtils::exitWithError("User unknown"); + uUtils::exitWithError($lang["userunknown"]); } } else { - uUtils::exitWithError("Unauthorized"); + uUtils::exitWithError($lang["notauthorized"]); } if ($passUser->setPass($pass) === false) { - uUtils::exitWithError("Server error"); + uUtils::exitWithError($lang["servererror"]); } $auth->updateSession(); uUtils::exitWithSuccess();