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 | ["username", security::PARAM_NEMPTY], |
| 7 | ["name", security::PARAM_NEMPTY], |
| 8 | ["dni", security::PARAM_ISSET], |
| 9 | ["email", security::PARAM_ISEMAILOREMPTY], |
| 10 | ["category", security::PARAM_NEMPTY], |
| 11 | ["password", security::PARAM_NEMPTY], |
| 12 | ["type", security::PARAM_ISSET] |
| 13 | ])) { |
| 14 | security::go("users.php?msg=empty"); |
| 15 | } |
| 16 | |
| 17 | if (!security::passwordIsGoodEnough($_POST["password"])) security::go("users.php?msg=weakpassword"); |
| 18 | |
| 19 | $username = $_POST["username"]; |
| 20 | $name = $_POST["name"]; |
| 21 | $dni = $_POST["dni"]; |
| 22 | $email = $_POST["email"]; |
| 23 | $category = (int)$_POST["category"]; |
| 24 | $password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT); |
| 25 | $type = (int)$_POST["type"]; |
| 26 | |
| 27 | if (!security::isAllowed($type)) security::go("users.php?msg=unexpected"); |
| 28 | |
| 29 | if (people::add($username, $name, $dni, $email, $category, $password_hash, $type)) { |
| 30 | security::go("users.php?msg=added"); |
| 31 | } else { |
| 32 | security::go("users.php?msg=unexpected"); |
| 33 | } |