blob: bf62372b58e2b9deeff31fd51d9ceb77cbe58c7b [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once("core.php");
3security::checkType(security::ADMIN);
4
5if (!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);
26if ($p === false) security::go("users.php?msg=unexpected");
27
28if (!security::isAllowed($type) || !security::isAllowed($p["type"]) || !categories::exists($category) || !security::existsType($type)) security::go("users.php?msg=unexpected");
29
30if (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
43security::go("users.php?msg=modified");