. */ require_once(dirname(__DIR__) . "/helpers/auth.php"); require_once(ROOT_DIR . "/helpers/utils.php"); $auth = new uAuth(); if (!$auth->isAuthenticated()) { $auth->sendUnauthorizedHeader(); uUtils::exitWithError("Unauthorized"); } $login = uUtils::postString('login'); $oldpass = uUtils::postPass('oldpass'); $pass = uUtils::postPass('pass'); // FIXME: strings need to be localized if (empty($pass)) { uUtils::exitWithError("Empty password"); } if ($auth->isAdmin() && !empty($login)) { // different user, only admin $passUser = new uUser($login); if (!$passUser->isValid) { uUtils::exitWithError("User unknown"); } } else if (!empty($login)) { uUtils::exitWithError("Unauthorized"); } else { // current user $passUser = $auth->user; if (!$passUser->validPassword($oldpass)) { uUtils::exitWithError("Wrong old password"); } } if ($passUser->setPass($pass) === false) { uUtils::exitWithError("Server error"); } uUtils::exitWithSuccess(); ?>