blob: af0951ca0ae40a5a67245bfb14a07f2780956e35 [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 ["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
17if (!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
27if (!security::isAllowed($type)) security::go("users.php?msg=unexpected");
28
29if (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}