This commit is contained in:
Wiesner András 2024-03-18 07:19:50 +01:00
parent b7bca5c6c1
commit c5dbb9ff87
7 changed files with 21 additions and 10 deletions

View File

@ -87,7 +87,7 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
<td><label for="time_limited">Időkorlátos:</label></td> <td><label for="time_limited">Időkorlátos:</label></td>
<td> <td>
<input type="checkbox" id="time_limited" oninput="handle_time_limit_chkbox()"> <input type="checkbox" id="time_limited" oninput="handle_time_limit_chkbox()">
<input type="time" id="time_limit" step="1"> <input type="text" pattern="(([01][0-9])|([2][0-3])):[0-5][0-9]:[0-5][0-9]" id="time_limit">
</td> </td>
</tr> </tr>
<tr> <tr>

View File

@ -56,6 +56,8 @@ if (!get_autologin_state() || ($user_data["privilege"] !== PRIVILEGE_QUIZMASTER)
<td><label for="group_owner">Tulajdonos:</label></td> <td><label for="group_owner">Tulajdonos:</label></td>
<td><input type="text" id="group_owner"></td> <td><input type="text" id="group_owner"></td>
</tr> </tr>
</table>
<table id="group_editor_additional_fields">
<tr> <tr>
<td><label for="group_editors">Szerkesztők:</label></td> <td><label for="group_editors">Szerkesztők:</label></td>
<td><input type="text" id="group_editors"></td> <td><input type="text" id="group_editors"></td>

View File

@ -6,12 +6,12 @@ require_once "usermgr.php";
$groupdb = new \SleekDB\Store(GROUPDB, DATADIR, ["timeout" => false]); $groupdb = new \SleekDB\Store(GROUPDB, DATADIR, ["timeout" => false]);
function create_group(string $groupname, string $owner, string $description = "", array $editors = []): bool function create_group(string $groupname, string $owner, string $description = ""): bool
{ {
global $groupdb; global $groupdb;
// test name uniqueness // test name uniqueness
$unique = clear_unique_in_siblings($groupname); $unique = manage_unique_in_siblings(0, $groupname);
// initialize group data // initialize group data
$group_data = [ $group_data = [
@ -19,7 +19,7 @@ function create_group(string $groupname, string $owner, string $description = ""
"unique" => $unique, "unique" => $unique,
"owner" => $owner, "owner" => $owner,
"description" => $description, "description" => $description,
"editors" => $editors, "editors" => [],
"users" => [], "users" => [],
"games" => [] "games" => []
]; ];
@ -122,11 +122,11 @@ function search_groups(string $needle): array
return $results; return $results;
} }
function clear_unique_in_siblings($groupname): bool function manage_unique_in_siblings(int $current_gid, $groupname): bool
{ {
// make test on name uniqueness // make test on name uniqueness
global $groupdb; global $groupdb;
$twins = $groupdb->findBy(["groupname", "=", "$groupname"]); $twins = $groupdb->findBy([["groupname", "=", "$groupname"], "AND", ["_id", "!=", $current_gid]]);
$unique = count($twins) == 0; $unique = count($twins) == 0;
if (count($twins) === 1) { // if fails, then also indicate in the original group that its name is no longer unique if (count($twins) === 1) { // if fails, then also indicate in the original group that its name is no longer unique
$twins[0]["unique"] = false; $twins[0]["unique"] = false;

View File

@ -268,14 +268,14 @@ switch ($action) {
if ($groupname != "") { if ($groupname != "") {
switch ($action) { switch ($action) {
case "create_group": case "create_group":
create_group($groupname, $owner, $description, $editors); create_group($groupname, $owner, $description);
break; break;
case "update_group": case "update_group":
{ {
$gid = $_REQUEST["id"]; $gid = $_REQUEST["id"];
$group = get_group($gid); $group = get_group($gid);
if (count($group) !== 0) { if (count($group) !== 0) {
$group["unique"] = clear_unique_in_siblings($groupname); // manage unique flag in case of renaming $group["unique"] = manage_unique_in_siblings($gid, $groupname); // manage unique flag in case of renaming
$group["groupname"] = $groupname; $group["groupname"] = $groupname;
$group["description"] = $description; $group["description"] = $description;
$group["editors"] = array_intersect($editors, $group["users"]); // a user cannot be an editor if not part of the group $group["editors"] = array_intersect($editors, $group["users"]); // a user cannot be an editor if not part of the group

View File

@ -95,6 +95,10 @@ function create_edit_game(game = null) {
submit_btn.onclick = () => { submit_btn.onclick = () => {
let game_name = document.getElementById("game_name").value.trim(); let game_name = document.getElementById("game_name").value.trim();
if (updating && time_limitedChk.checked && time_limitF.validity.patternMismatch) {
alert("Hibás időformátum!")
return;
}
if (game_name !== "") { if (game_name !== "") {
let reqData = { let reqData = {
name: game_name, name: game_name,

View File

@ -49,6 +49,7 @@ function create_edit_group(group = null) {
group_ownerF.readOnly = true; group_ownerF.readOnly = true;
group_editorsF.value = ""; group_editorsF.value = "";
group_membersF.value = ""; group_membersF.value = "";
hide("group_editor_additional_fields");
} else { // update and existing one } else { // update and existing one
groupnameF.value = group["groupname"]; groupnameF.value = group["groupname"];
group_descriptionF.value = group["description"]; group_descriptionF.value = group["description"];
@ -57,6 +58,7 @@ function create_edit_group(group = null) {
group_ownerF.readOnly = false; group_ownerF.readOnly = false;
group_editorsF.value = group["editors"].join(", "); group_editorsF.value = group["editors"].join(", ");
group_membersF.value = group["users"].join(", "); group_membersF.value = group["users"].join(", ");
show("group_editor_additional_fields");
} }
submit_btn.onclick = () => { submit_btn.onclick = () => {

View File

@ -9,7 +9,7 @@ const PRIVILEGE_PLAYER = "player";
const PRIVILEGE_CREATOR = "creator"; const PRIVILEGE_CREATOR = "creator";
const PRIVILEGE_QUIZMASTER = "admin"; // TODO: refactor! const PRIVILEGE_QUIZMASTER = "admin"; // TODO: refactor!
function add_user(string $nickname, string $password, string $realname, array $groups = [], string $privilege = PRIVILEGE_PLAYER): bool function add_user(string $nickname, string $password, string $realname, array $groupids = [], string $privilege = PRIVILEGE_PLAYER): bool
{ {
global $userdb; global $userdb;
if (count(get_user($nickname)) != 0) { // user exists if (count(get_user($nickname)) != 0) { // user exists
@ -20,9 +20,12 @@ function add_user(string $nickname, string $password, string $realname, array $g
"nickname" => $nickname, "nickname" => $nickname,
"password" => password_hash($password, PASSWORD_DEFAULT), "password" => password_hash($password, PASSWORD_DEFAULT),
"realname" => $realname, "realname" => $realname,
"groups" => $groups, "groups" => $groupids,
"privilege" => $privilege "privilege" => $privilege
]; ];
foreach ($groupids as $groupid) {
change_group_user_assignments($groupid, $nickname, null);
}
$userdb->insert($user_data); $userdb->insert($user_data);
return true; // user registration successful return true; // user registration successful
} }