Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | require_once("core.php"); |
| 3 | security::checkType(security::ADMIN); |
| 4 | |
| 5 | if (!security::checkParams("POST", [ |
| 6 | ["id", security::PARAM_NEMPTY], |
| 7 | ["username", security::PARAM_NEMPTY], |
| 8 | ["name", security::PARAM_NEMPTY], |
| 9 | ["dni", security::PARAM_ISSET], |
| 10 | ["email", security::PARAM_ISEMAILOREMPTY], |
| 11 | ["category", security::PARAM_NEMPTY], |
| 12 | ["type", security::PARAM_ISSET] |
| 13 | ])) { |
| 14 | security::go("users.php?msg=empty"); |
| 15 | } |
| 16 | |
| 17 | $id = (int)$_POST["id"]; |
| 18 | $username = $_POST["username"]; |
| 19 | $name = $_POST["name"]; |
| 20 | $dni = $_POST["dni"]; |
| 21 | $email = $_POST["email"]; |
| 22 | $category = (int)$_POST["category"]; |
| 23 | $type = (int)$_POST["type"]; |
| 24 | |
| 25 | $p = people::get($id); |
| 26 | if ($p === false) security::go("users.php?msg=unexpected"); |
| 27 | |
| 28 | if (!security::isAllowed($type) || !security::isAllowed($p["type"]) || !categories::exists($category) || !security::existsType($type)) security::go("users.php?msg=unexpected"); |
| 29 | |
| 30 | if (people::edit($id, $username, $name, $dni, $email, $category, $type)) { |
| 31 | if (security::checkParams("POST", [["password", security::PARAM_NEMPTY]])) { |
| 32 | if (!security::passwordIsGoodEnough($_POST["password"])) security::go("users.php?msg=weakpassword"); |
| 33 | |
| 34 | $password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT); |
| 35 | if (!people::updatePassword($id, $password_hash)) { |
| 36 | security::go("users.php?msg=couldntupdatepassword"); |
| 37 | } |
| 38 | } |
| 39 | } else { |
| 40 | security::go("users.php?msg=unexpected"); |
| 41 | } |
| 42 | |
| 43 | security::go("users.php?msg=modified"); |